[Bug other/83520] format string bug in libvtv

2021-11-11 Thread egallager at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83520

Eric Gallager  changed:

   What|Removed |Added

 CC||egallager at gcc dot gnu.org

--- Comment #4 from Eric Gallager  ---
(In reply to Touma Hatano from comment #3)
> Sorry for misleading.
> My point was that if we can replace
>   snprintf (program_name, sizeof (program_name), program_invocation_name);
> with
>   snprintf (program_name, sizeof (program_name), "%s",
> program_invocation_name);
> , the program won't crash when program_invocation_name contains format
> specifiers.
> 
> How do you think?

Shouldn't -Wformat-security catch this? If it doesn't, that's a bug, IMO...

[Bug other/83520] format string bug in libvtv

2017-12-24 Thread charo.ctf at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83520

--- Comment #3 from Touma Hatano  ---
Sorry for misleading.
My point was that if we can replace
  snprintf (program_name, sizeof (program_name), program_invocation_name);
with
  snprintf (program_name, sizeof (program_name), "%s",
program_invocation_name);
, the program won't crash when program_invocation_name contains format
specifiers.

How do you think?

[Bug other/83520] format string bug in libvtv

2017-12-21 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83520

Jakub Jelinek  changed:

   What|Removed |Added

 CC||ctice at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
"should just use program_name instead of program_invocation_name"
I meant the opposite obviously.

[Bug other/83520] format string bug in libvtv

2017-12-21 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83520

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
There is another
  snprintf (program_name, sizeof (program_name), program_invocation_name);
elsewhere, also
  /* Find the first non-escaped space in the program name and make it
 the end of the string.  */
  cptr = strchr (program_name, ' ');
  if (cptr != NULL && cptr[-1] != '\\')
cptr[0] = '\0';
stuff (what would escape anything in the program_invocation_name or getexecname
() result)?
GNU C library certainly doesn't and doesn't append any arguments there either,
so at least for glibc it should just use program_name instead of
program_invocation_name and remove this copying and munging.  Just tried
running a program with spaces in the filename and nothing was escaped.
Now, if there is anything that actually escapes, then it should be done only on
targets where it is escaped, and I'd expect that \s in that case would be two
backslash characters, so running 'abc\' program with argument 'def' would
result in "abc def" program_name.  The condition also doesn't find the
first non-escaped space, just checks if the first space isn't even potentially
escaped, otherwise does nothing.
In the second case with
  snprintf (program_name, sizeof (program_name), program_invocation_name);
there is no attempt to do modify program_name in any way, so I don't see any
reason not to use program_invocation_name directly and avoid any copying
whatsoever.