Skip to content

Commit

Permalink
Switched away from sprintf, which is prone to buffer overflows.
Browse files Browse the repository at this point in the history
Most reasonable platforms have this function. If you're here because
this broke the build for you, consider adding an ifdef for your platform
and using sprintf there (but not on other platforms).
  • Loading branch information
jacobsa committed Aug 6, 2013
1 parent 700b380 commit 42d918b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ Reader::getLocationLineAndColumn( Location location ) const
int line, column;
getLocationLineAndColumn( location, line, column );
char buffer[18+16+16+1];
sprintf( buffer, "Line %d, Column %d", line, column );
snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
return buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::string valueToString( double value )
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning.
sprintf_s(buffer, sizeof(buffer), "%#.16g", value);
#else
sprintf(buffer, "%#.16g", value);
snprintf(buffer, sizeof(buffer), "%#.16g", value);
#endif
char* ch = buffer + strlen(buffer) - 1;
if (*ch != '0') return buffer; // nothing to truncate, so save time
Expand Down

0 comments on commit 42d918b

Please sign in to comment.