Skip to content

Conversation

@jmikola
Copy link
Member

@jmikola jmikola commented Jun 21, 2018

No description provided.

jmikola added 2 commits June 21, 2018 15:36
bson_ascii_strtoll() resets errno, so that is no longer necessary. This also removes some outdated comments.
@jmikola jmikola requested a review from derickr June 21, 2018 19:39
efree(tmp);
s_milliseconds_len = snprintf(s_milliseconds, sizeof(s_milliseconds), "%" PRId64, intern->milliseconds);

PHONGO_RETVAL_STRINGL(s_milliseconds, s_milliseconds_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for making this change? The use of snprintf is potentially unsafe due to strange \0 termination rules, and spprintf is preferred.

Copy link
Member Author

Choose a reason for hiding this comment

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

jsonSerialize(), which is effectively the same thing, was already using snprintf() with a static buffer (24 is sufficient to hold INT64_MIN and the null byte).

I don't follow why this would be potentially unsafe. My understanding is that snprintf() always adds a null byte (at the expense of the string it's printing if it were to approach the buffer size). See: https://stackoverflow.com/q/7706936/162228. This makes it safer than sprintf() (risk of no termination) and comparable to spprintf(), which would also always terminate the allocated string.

Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

lgtm

@jmikola jmikola merged commit ae98012 into mongodb:master Jun 22, 2018
jmikola added a commit that referenced this pull request Jun 22, 2018
@jmikola jmikola deleted the bson-fixups branch June 22, 2018 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants