Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed int to SQLLEN to avoid infinite loop #806

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/shared/core_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ SQLRETURN binary_to_string( _Inout_ SQLCHAR* field_data, _Inout_ SQLLEN& read_so
// to_copy contains the number of bytes to copy, so we divide the number in half (or quarter)
// to get the number of hex digits we can copy
SQLLEN to_copy_hex = to_copy / (2 * extra);
for( int i = 0; i < to_copy_hex; ++i ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this possibly result in an infinite loop?

Copy link
Contributor Author

@yitam yitam Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since to_copy_hex (SQLLEN) may be 8 bytes and i is only 4, if the value of to_copy_hex is greater than MAX_INT, the loop will never end.

for( SQLLEN i = 0; i < to_copy_hex; ++i ) {
*h = hex_chars[ (*b & 0xf0) >> 4 ];
h++;
*h = hex_chars[ (*b++ & 0x0f) ];
Expand Down