public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
* [Bug 1001490] New: C99 snprintf() does not include terminated null in truncated strings
@ 2012-02-19 13:11 bugzilla-daemon
  2012-06-27 18:37 ` [Bug 1001490] " bugzilla-daemon
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: bugzilla-daemon @ 2012-02-19 13:11 UTC (permalink / raw)
  To: ecos-patches

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001490

           Summary: C99 snprintf() does not include terminated null in
                    truncated strings
           Product: eCos
           Version: CVS
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: enhancement
          Priority: low
         Component: Patches and contributions
        AssignedTo: unassigned@bugs.ecos.sourceware.org
        ReportedBy: sergei.gavrikov@gmail.com
                CC: ecos-patches@ecos.sourceware.org
             Class: Advice Request


Created an attachment (id=1587)
 --> (http://bugs.ecos.sourceware.org/attachment.cgi?id=1587)
add null terminator for truncated strings;  fix checks in stdio sprintf2.c test

SNPRINTF(3)

        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.

But, truncated string of eCos "C99" snprintf() does not include the
terminating null byte ('\0').

You would see this bug running eCos stdio `sprintf2' test, if

  cdl_option CYGIMP_LIBC_STDIO_C99_SNPRINTF {
      user_value 1
  };

applied. For example, this is a case when you add eCos USTL package
which claims CYGIMP_LIBC_STDIO_C99_SNPRINTF.

Then a built `sprintf2' test (it uses a few checks for snprintf()) fails on

  FAIL:<simple snprintf test #1> Line: 138, File:
language/c/libc/stdio/current/tests/sprintf2.c
  FAIL:<simple snprintf test #1 return code> Line: 140, File:
language/c/libc/stdio/current/tests/sprintf2.c
  FAIL:<simple snprintf test #2> Line: 145, File:
language/c/libc/stdio/current/tests/sprintf2.c
  FAIL:<simple snprintf test #2 return code> Line: 147, File:
language/c/libc/stdio/current/tests/sprintf2.c
  FAIL:<snprintf double test #1> Line: 169, File:
language/c/libc/stdio/current/tests/sprintf2.c
  FAIL:<snprintf double test #1 return code> Line: 172, File:
language/c/libc/stdio/current/tests/sprintf2.c
  EXIT:<Finished tests from testcase
language/c/libc/stdio/current/tests/sprintf2.c for C library sprintf()
function>

The fails on checks the 'return code' (lines 140, 147, and 172) are okay
due C99 snprintf() return value.

But checks on lines 138, 145, and 169 are "strcmp()" checks and they
should not fail if snprintf() implemented properly.

Workaround is to add additional check and set the terminator in eCos
vsnprintf.cxx, see an attached patch. Also the patch adds proper checks
for return codes in sprintf2.c test if C99 implementation snprintf()
uses. With applied patch all snprintf() checks pass as we could expect.

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

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

end of thread, other threads:[~2013-02-19 13:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-19 13:11 [Bug 1001490] New: C99 snprintf() does not include terminated null in truncated strings bugzilla-daemon
2012-06-27 18:37 ` [Bug 1001490] " bugzilla-daemon
2012-08-07 10:06 ` bugzilla-daemon
2012-08-07 16:44 ` bugzilla-daemon
2012-08-08  7:31 ` bugzilla-daemon
2012-08-08 16:58 ` bugzilla-daemon
2012-08-09  7:50 ` bugzilla-daemon
2012-08-09  8:52 ` bugzilla-daemon
2012-08-09 10:00 ` bugzilla-daemon
2012-08-09 10:52 ` bugzilla-daemon
2012-08-09 11:04 ` bugzilla-daemon
2013-02-18 22:00 ` bugzilla-daemon
2013-02-19 10:40 ` bugzilla-daemon
2013-02-19 13:58 ` bugzilla-daemon

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).