After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 122973 - Cleanups to import of glib/gnulib
Cleanups to import of glib/gnulib
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other other
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2003-09-22 20:28 UTC by The Written Word
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (5.81 KB, patch)
2003-09-22 20:28 UTC, The Written Word
none Details | Review

Description The Written Word 2003-09-22 20:28:18 UTC
The code in glib/gnulib is broken for all platforms (and even Linux when
--enable-included-printf is specified). The attached patch fixes all problems:
  1. [configure.in]
     Don't define HAVE_C99_VSNPRINTF and HAVE_C99_SNPRINTF
     when the included printf is used
  2. [glib/gnulib/README]
     Fix up glib/gnulib/README
  3. [glib/gnulib/g-gnulib.h, glib/gnulib/printf.c]
     Setting HAVE_SNPRINTF depending on HAVE_C99_SNPRINTF is confusing.
     In glib/gnulib/printf.c use HAVE_C99_SNPRINTF instead. Accomplishes
     the same thing while not being confusing.
  4. [glib/gnulib/printf.c]
     Fix off-by-one errors in glib/gnulib/printf.c. The _g_gnulib_v*printf
     functions seem to set length to the length of the string + 1 for
     the trailing '\0';
Comment 1 The Written Word 2003-09-22 20:28:35 UTC
Created attachment 20195 [details] [review]
Patch
Comment 2 Matthias Clasen 2003-10-04 23:27:21 UTC
I committed 1 and 2, decided that 3 isn't really confusing (the aim
here is to stay as close to gnulib as possible, thus we're doing some
modifications via cpp rather than sed). Regarding 4, I agree that
fprintf must not write the trailing nul out to the file, but thats the
only off-by-one error I see. If there are any others, testcases would
be appreciated.
Comment 3 The Written Word 2003-10-05 02:14:35 UTC
Everything referencing length+1 is an off-by-one error. On GNU/Linux,
force building of gnulib by passing --enable-included-printf to
./configure. Then, look at the output of the files created by
glib-genmarshal. You'll see \0 characters in the output. The tests
pass but these characters exist in the output.
Comment 4 Matthias Clasen 2003-10-05 15:47:50 UTC
No, it is not. length refers to the length of the string without the
trailing nul, so if you want to copy the string including the trailing
nul, you have to use length + 1. That covers all uses besides the one in
fprintf() which is reponsible for the glib-genmarshal problems you
mention, and which I fixed yesterday...
Comment 5 The Written Word 2003-10-05 17:38:15 UTC
_g_gnulib_vfprintf() calls vasnprintf. This contains an off-by-one
error we both agree on. However, _g_gnulib_vsprintf() also calls
vasnprintf. How is length+1 valid in _g_gnulib_vsprintf() and not in
_g_gnulib_vfprintf()?
Comment 6 Matthias Clasen 2003-10-05 20:26:02 UTC
length is the length of the returned string, ie strlen(result).
length + 1 is the number of bytes which has been allocated.
length + 1 wasn't invalid in fprintf in the sense of array bounds
violation, but fprintf shouldn't write the final byte (which is the 
trailing nul) to the file.