This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
[Bug 1001490] New: C99 snprintf() does not include terminated null in truncated strings
- From: bugzilla-daemon at bugs dot ecos dot sourceware dot org
- To: ecos-patches at ecos dot sourceware dot org
- Date: Sun, 19 Feb 2012 13:11:02 +0000
- Subject: [Bug 1001490] New: C99 snprintf() does not include terminated null in truncated strings
- Auto-submitted: auto-generated
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.