public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96826] New: missing warning appending to the result of strdup
@ 2020-08-27 22:06 msebor at gcc dot gnu.org
  2020-08-27 22:07 ` [Bug tree-optimization/96826] " msebor at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-08-27 22:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96826

            Bug ID: 96826
           Summary: missing warning appending to the result of strdup
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Appending to a string created by strdup is not diagnosed by could be by looking
up the origin of the destination pointer and, if it's used in a call to a
function like strcat, or if it's accessed at an offset derived from strlen of
either the copy or the original (with no subtraction), issuing
-Wstringop-overflow.

$ cat z.c && /build/gcc-master/gcc/xgcc -B /build/gcc-master/gcc -O2 -S -Wall
z.c
void* f0 (const char *s)
{
  char *t = __builtin_strdup (s);
  __builtin_strcat (t, "xyz");      // missing warning
  return t;
}

void* f1 (const char *s)
{ 
  char *t = __builtin_strdup (s);
  t += __builtin_strlen (t);
  t[0] = 'x';
  t[1] = 'y';                       // missing warning
  t[2] = 'z';                       // ditto
  return t;
}

void* f2 (const char *s)
{ 
  char *t = __builtin_strdup (s);
  t += __builtin_strlen (t);
  __builtin_sprintf (t, "%i", 123); // missing warning
  return t;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug tree-optimization/96826] missing warning appending to the result of strdup
  2020-08-27 22:06 [Bug tree-optimization/96826] New: missing warning appending to the result of strdup msebor at gcc dot gnu.org
@ 2020-08-27 22:07 ` msebor at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-08-27 22:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96826

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |83819
           Keywords|                            |diagnostic
           Severity|normal                      |enhancement

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Since it tracks all these calls the strlen pass is probably the most suitable
place to implement the warning.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819
[Bug 83819] [meta-bug] missing strlen optimizations

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-27 22:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 22:06 [Bug tree-optimization/96826] New: missing warning appending to the result of strdup msebor at gcc dot gnu.org
2020-08-27 22:07 ` [Bug tree-optimization/96826] " msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).