[PATCH] handle local aggregate initialization in strlen, take 2 (PR 83821)

Martin Sebor msebor@gmail.com
Tue Oct 15 02:34:00 GMT 2019


When a subsequent element or member of a local aggregate containing
a prior character array is initialized the strlen pass discards
the length it computed for the prior element/member.  E.g., here:

   struct { char a[4], b[4]; } s = { "1", "12" };

even though strlen (s.b) is folded to 2, strlen (s.a) is not.  (Ditto
for other stores even to members of other types.)  This causes hundreds
(over 700 in GCC) to thousands (nearly 3,000 in Binutils/GDB and some
36,000 in the kernel) of instances of previously computed string lengths
to end up discarded and so besides emitting less than optimal code also
defeats buffer overflow detection in such cases.

Attached is a resubmission of a previously approved patch that I never
committed (the original had a bug that was noted during review that
I subsequently fixed but I didn't remember to post the corrected patch).
Tested on x86_64-linux.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-83821.diff
Type: text/x-patch
Size: 23530 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20191015/5c471b1c/attachment.bin>


More information about the Gcc-patches mailing list