-
Notifications
You must be signed in to change notification settings - Fork 394
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
Improve handling of some buffer size limits. #422
Conversation
Lets us handle very long CSV lines and very big SIP messages. Example usage: ./build.sh --with-openssl CPPFLAGS=-DBUFFER_SIZE_MULTIPLIER=16
Hi! Thanks for the PR. But I don't like this fix. What kind of SIP messages do you have that could possibly exceed 64K? Do you have examples or (even better) a test case that triggers these crashes? |
Hello. Thanks for responding. In our use case, the very large messages are NOTIFY message which contain big RLS contact lists in XML format. Here are some related RFC resources: https://tools.ietf.org/html/rfc4662 Some of our users have massive contact lists, and our SIP server will generate big NOTIFY messages and send them as a single SIP message over TLS. Here's a redacted version of one such large NOTIFY message: I will look into adding a unit test which triggers the problems I mentioned. Thanks again. |
Initially, I was thinking that it would be nice to convert all the relevant fixed-size arrays into dynamically sized std::vector objects, but I suspect that would require a lot more code changes. |
Hello. Instead of a multiplier, an alternate idea would be to allow for the individual buffer sizes to be overridden independently with separate CPPFLAGS. Would that be more desirable? Thanks. |
Well. I think enlarging the SIPP_MAX_MSG_SIZE makes sense (if it can be done dynamically, it'd be even better, but might be troublesome). Enlarging the screen_last_error doesn't make sense to me. Who needs a large blob of >32k in their screen output? This is to prevent a crash, am I right? In that case the appropriate length-checking functions strNcpy, sNprintf or whatever should be used to fix those. As for MAX_CHAR_BUFFER_SIZE: that's only a problem for you in FileContents::FileContent (infile.cpp) right? That can be solved by using more std::stuff and fewer char[]s. |
Thanks for the feedback. I agree with your suggestions. I will make some changes in the next week or so along those lines, then ask for another review. Would you prefer to have SIPP_MAX_MSG_SIZE increased arbitrarily by some amount, like 4X, or would you prefer that it be configurable with a CPPFLAG? If configurable, the code would look something like this:
This would allow me to build as follows to meet my needs: ./build.sh --with-openssl CPPFLAGS=-DSIPP_MAX_MSG_SIZE=262144 Thanks again. |
Instead of using a buffer size multiplier, we now allow only SIPP_MAX_MSG_SIZE to be adjusted with a compile-time flag. For the other buffer limits I was hitting, I've tried to add safety in better ways.
Hello. I've taken another pass at it. I still have to do some more testing, but please let me know if this is moving in the right direction. I stopped short of doing a big refactor of parsing code and went with a compromise approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was what I was thinking indeed 👍
src/screen.cpp
Outdated
c+= vsprintf(c, fmt, ap); | ||
const std::size_t bufSize = sizeof(screen_last_error)/sizeof(screen_last_error[0]); | ||
c+= snprintf(c, bufSize, "%s: ", CStat::formatTime(¤tTime)); | ||
c+= vsnprintf(c, (bufSize - (c - screen_last_error)), fmt, ap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add spaces around /
and +=
.
(When you're touching lines, might as well fix the code style.)
And, you cannot add the return value of (v)snprintf() to c, because:
If the output was truncated due to this limit, then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available.
So that'll need fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the return value. Turns out I also need to check for a negative return value. I've just pushed a new version of the fix. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the changes are working well. I was able to do a fair amount of testing.
Hello.
Several of my scenarios use TCP/TLS with very large SIP messages, and I was running into buffer size limitations which caused crashes or errors.
My changes allow a new CPPFLAG to increase the size of a few important buffers in the code.
Example usage:
./build.sh --with-openssl CPPFLAGS=-DBUFFER_SIZE_MULTIPLIER=16
Thanks for the consideration.