Thread overview
[Issue 23648] Replace all sprintf with snprintf
Jan 30, 2023
Dlang Bot
Feb 03, 2023
Dlang Bot
Feb 06, 2023
kdevel
Feb 06, 2023
kdevel
Feb 27, 2023
Iain Buclaw
Jul 10, 2023
RazvanN
January 30, 2023
https://issues.dlang.org/show_bug.cgi?id=23648

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #1 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 updated dlang/dmd pull request #14854 "Fix Issue 23658 - replace uses of sprintf with snprintf in the compiler" fixing this issue:

- Fix Issue 23648 - replace uses of sprintf with snprintf in the compiler

https://github.com/dlang/dmd/pull/14854

--
February 03, 2023
https://issues.dlang.org/show_bug.cgi?id=23648

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #14854 "Fix Issue 23648 - replace uses of sprintf with snprintf in the compiler" was merged into master:

- 3c51a0c69e4796fb6a29bc08a1be5207b8d66d1f by RazvanN7:
  Fix Issue 23648 - replace uses of sprintf with snprintf in the compiler

https://github.com/dlang/dmd/pull/14854

--
February 06, 2023
https://issues.dlang.org/show_bug.cgi?id=23648

kdevel <kdevel@vogtner.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kdevel@vogtner.de

--
February 06, 2023
https://issues.dlang.org/show_bug.cgi?id=23648

kdevel <kdevel@vogtner.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #3 from kdevel <kdevel@vogtner.de> ---
(In reply to johanengelen from comment #0)
> sprintf may write beyond the buffer passed, snprintf is the safer option.

The origininal problem was writing beyond the buffer. By replacing sprintf with snprintf the problem now is truncation which goes unnoticed. Why not detect and throw if truncation occurs?

import core.stdc.stdarg;
extern (C) size_t snprintf_without_silent_truncation (char *s, size_t len,
const char *fmt, ...)
{
   import std.exception;
   import std.stdio;
   import std.format;
   va_list args;
   va_start (args, fmt);
   auto rc = vsnprintf (s, len, fmt, args);
   va_end (args);
   enforce (rc >= 0, "vsnprintf failed");
   enforce (rc < len, format!"vsnprintf: tried to write %d B + \\0 into buffer
of size %d B" (rc, len));
   return rc;
}

--
February 27, 2023
https://issues.dlang.org/show_bug.cgi?id=23648

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--
July 10, 2023
https://issues.dlang.org/show_bug.cgi?id=23648

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |FIXED

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
The bug report has been closed because the initial claim has been resolved. Please do not reopen bug reports, instead file new ones.

However, for this particular case I don't think that is necessary since underflow is not an issue.

--