From: bugzilla-daemon@bugs.ecos.sourceware.org
To: ecos-patches@ecos.sourceware.org
Subject: [Bug 1001490] New: C99 snprintf() does not include terminated null in truncated strings
Date: Sun, 19 Feb 2012 13:11:00 -0000 [thread overview]
Message-ID: <bug-1001490-104@http.bugs.ecos.sourceware.org/> (raw)
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.
next reply other threads:[~2012-02-19 13:11 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-19 13:11 bugzilla-daemon [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-1001490-104@http.bugs.ecos.sourceware.org/ \
--to=bugzilla-daemon@bugs.ecos.sourceware.org \
--cc=ecos-patches@ecos.sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).