Closed Bug 1434070 Opened 6 years ago Closed 5 years ago

Fix signtool to build with gcc 8

Categories

(NSS :: Libraries, defect, P3)

3.36
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1437734

People

(Reporter: KaiE, Assigned: KaiE)

References

Details

Attachments

(1 file)

When building cmd/signtool/sign.c with gcc 8, we get multiple occurrences of the following error:

sign.c: In function 'SignArchive':
sign.c:86:31: error: '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Werror=format-overflow=]
         sprintf(fullfn, "%s/%s", tree, tempfn);
                               ^
In file included from /usr/include/stdio.h:862,
                 from signtool.h:10,
                 from sign.c:5:
/usr/include/bits/stdio2.h:33:10: note: '__builtin___sprintf_chk' output 2 or more bytes (assuming 257) into a destination of size 256
   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       __bos (__s), __fmt, __va_arg_pack ());
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Converting sprintf to snprintf is still insufficient, it produces another error, which complains that the resulting data might be truncated.

Using snprintf and checking the result fixes it.

From the manpage:

"The  functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')).  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.   Thus,  a
return value of size or more means that the output was truncated.  (See also below under NOTES.)"

Checking the return value for "size or more" seems the right thing to do, and fixes the compiler error.
Assignee: nobody → kaie
This was the quick-and-dirty patch to get it built.

A follow-up patch could avoid duplication of the error handling code and move it to a function.
Priority: -- → P3
Blocks: build-gcc-8

It seems this was fixed through bug 1437734. Maybe we can close this as DUPLICATE?

Flags: needinfo?(kaie)
QA Contact: jjones

Marking as dupe based on comment 3.

Status: NEW → RESOLVED
Closed: 5 years ago
Flags: needinfo?(kaie)
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: