[GH-ISSUE #2533] New warnings generated by GCC 7 #1668

Closed
opened 2026-10-15 04:22:07 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @kholia on GitHub (May 8, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2533

While building JtR jumbo with GCC 7 I see,

dynamic_fmt.c: In function ‘prepare’:
dynamic_fmt.c:8212:19: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
      sprintf(Fld, "$$F%d", i);
                   ^~~~~~~
dynamic_fmt.c:8212:6: note: ‘sprintf’ output between 5 and 6 bytes into a destination of size 5
      sprintf(Fld, "$$F%d", i);
      ^~~~~~~~~~~~~~~~~~~~~~~~

sip_fmt_plug.c: In function ‘get_salt’:
sip_fmt_plug.c:261:61: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 57 and 311 [-Wformat-truncation=]
   snprintf(salt.static_hash_data, STATIC_HASH_SIZE, ":%s:%s:%s:%s:%s",
                                                             ^~
     login.nonce, login.nonce_count, login.cnonce,
                                     ~~~~~
sip_fmt_plug.c:261:3: note: ‘snprintf’ output 6 or more bytes (assuming 398) into a destination of size 314
   snprintf(salt.static_hash_data, STATIC_HASH_SIZE, ":%s:%s:%s:%s:%s",
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     login.nonce, login.nonce_count, login.cnonce,
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     login.qop, static_hash);
     ~~~~~~~~~~~~~~~~~~~~~~~

gcc-7-compilation-log.txt (full log).

I have not investigated these compiler warning messages.

Originally created by @kholia on GitHub (May 8, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2533 While building JtR jumbo with GCC 7 I see, ``` dynamic_fmt.c: In function ‘prepare’: dynamic_fmt.c:8212:19: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=] sprintf(Fld, "$$F%d", i); ^~~~~~~ dynamic_fmt.c:8212:6: note: ‘sprintf’ output between 5 and 6 bytes into a destination of size 5 sprintf(Fld, "$$F%d", i); ^~~~~~~~~~~~~~~~~~~~~~~~ sip_fmt_plug.c: In function ‘get_salt’: sip_fmt_plug.c:261:61: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 57 and 311 [-Wformat-truncation=] snprintf(salt.static_hash_data, STATIC_HASH_SIZE, ":%s:%s:%s:%s:%s", ^~ login.nonce, login.nonce_count, login.cnonce, ~~~~~ sip_fmt_plug.c:261:3: note: ‘snprintf’ output 6 or more bytes (assuming 398) into a destination of size 314 snprintf(salt.static_hash_data, STATIC_HASH_SIZE, ":%s:%s:%s:%s:%s", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ login.nonce, login.nonce_count, login.cnonce, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ login.qop, static_hash); ~~~~~~~~~~~~~~~~~~~~~~~ ``` [gcc-7-compilation-log.txt](https://github.com/magnumripper/JohnTheRipper/files/983386/gcc-7-compilation-log.txt) (full log). I have not investigated these compiler warning messages.
bsakaguchi 2026-10-15 04:22:07 +07:00
Author
Owner

@jfoug commented on GitHub (May 8, 2017):

dynamic_fmt.c: In function ‘prepare’:
dynamic_fmt.c:8212:19: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
sprintf(Fld, "$$F%d", i);
^~~~~~~
dynamic_fmt.c:8212:6: note: ‘sprintf’ output between 5 and 6 bytes into a destination of size 5
sprintf(Fld, "$$F%d", i);
^~~~~~~~~~~~~~~~~~~~~~~~

That is a 100% bogus message. The output will ALWAYS be 4 bytes + 1 byte null. The 'fancy' new compiler is simply too smart for its own good. There is a for loop, for (x = 0; x < 10; ++x) I guess we could change it to <= 9 to pacify the stupid compiler warning (hopefully that will remove the warning). Same end result, but no warning.

<!-- gh-comment-id:299904536 --> @jfoug commented on GitHub (May 8, 2017): > dynamic_fmt.c: In function ‘prepare’: dynamic_fmt.c:8212:19: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=] sprintf(Fld, "$$F%d", i); ^~~~~~~ dynamic_fmt.c:8212:6: note: ‘sprintf’ output between 5 and 6 bytes into a destination of size 5 sprintf(Fld, "$$F%d", i); ^~~~~~~~~~~~~~~~~~~~~~~~ That is a 100% bogus message. The output will ALWAYS be 4 bytes + 1 byte null. The 'fancy' new compiler is simply too smart for its own good. There is a for loop, ``` for (x = 0; x < 10; ++x) ``` I guess we could change it to ```<= 9``` to pacify the stupid compiler warning (hopefully that will remove the warning). Same end result, but no warning.
Author
Owner

@kholia commented on GitHub (May 16, 2017):

https://gcc.gnu.org/gcc-7/changes.html is relevant to this discussion. The i variable is a signed int, and the compiler falsely thinks that it can be negative. Hence, the compiler says that the sprintf output can be 6 bytes (one extra byte for the - sign character).

Yes, this seems to be a bogus warning.

<!-- gh-comment-id:301677328 --> @kholia commented on GitHub (May 16, 2017): https://gcc.gnu.org/gcc-7/changes.html is relevant to this discussion. The `i` variable is a signed int, and the compiler falsely thinks that it can be negative. Hence, the compiler says that the sprintf output can be 6 bytes (one extra byte for the `-` sign character). Yes, this seems to be a bogus warning.
Author
Owner

@magnumripper commented on GitHub (May 18, 2017):

Is this a stable gcc or some bleeding-edge beta?

<!-- gh-comment-id:302538874 --> @magnumripper commented on GitHub (May 18, 2017): Is this a stable gcc or some bleeding-edge beta?
Author
Owner

@magnumripper commented on GitHub (May 18, 2017):

So according to that document we should either bump size of Fld or make i unsigned (assuming this is a stable gcc).

<!-- gh-comment-id:302539776 --> @magnumripper commented on GitHub (May 18, 2017): So according to that document we should either bump size of `Fld` or make `i` unsigned (assuming this is a stable gcc).
Author
Owner

@kholia commented on GitHub (May 19, 2017):

These warnings are generated by stable GCC which will be shipping with Fedora 26.

<!-- gh-comment-id:302605475 --> @kholia commented on GitHub (May 19, 2017): These warnings are generated by stable GCC which will be shipping with Fedora 26.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1668
No description provided.