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

Buffer overflow in getDateTime() #1

Closed
welchr opened this issue Nov 19, 2013 · 5 comments
Closed

Buffer overflow in getDateTime() #1

welchr opened this issue Nov 19, 2013 · 5 comments
Labels

Comments

@welchr
Copy link

welchr commented Nov 19, 2013

We had an issue where the program would terminate abnormally, and it looks like the culprit was snprintf() in the function getDateTime(). The char buffer is 100 bytes, but snprintf attempts to write 126. The compiler also gives a warning about it that I didn't notice originally:

In function ‘int snprintf(char*, size_t, const char*, ...)’,
inlined from ‘std::string getDateTime(const time_t&)’ at utils.cpp:172:48:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:66:44: warning: call to int __builtin___snprintf_chk(char*, long unsigned int, int, long unsigned int, const char*, ...) will always overflow destination

Changing char buffer[100] to char buffer[126] within that function solved the problem for us.

@timflutre
Copy link
Owner

Yes, thanks. It will be corrected in v1.3. But it sounds strange that this was causing the program to terminate abnormally. The char array only contains year, month, day, hours, minutes and seconds. So it should always use less than 100 characters, right? I'm asking this because neither me nor any other user has ever had the program terminate because of that.

@welchr
Copy link
Author

welchr commented Nov 19, 2013

It looks like it's something GCC does to protect against overflows:

http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html
http://thexploit.com/secdev/turning-off-buffer-overflow-protections-in-gcc/

Maybe that __builtin___snprintf_chk() function is being called to check the size of the destination and the assertion is failing. Not sure why on our system it causes the program to fault but not on others - maybe our system or version of GCC has those overflow protections enabled by default?

@timflutre
Copy link
Owner

Ok, thanks a lot for your detailed answer. Does it work fine for you when using "char buffer[128];" instead of "char buffer[100];"?

@welchr
Copy link
Author

welchr commented Nov 21, 2013

It sure does.

Thanks again for the wonderful program. We're looking forward to seeing what comes out of the analysis...

@timflutre
Copy link
Owner

fixed in v1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants