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 74336 - iconv() with null arguments segfaults on sunos
iconv() with null arguments segfaults on sunos
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
1.3.x
Other opensolaris
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2002-03-12 09:05 UTC by Lauri Alanko
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Lauri Alanko 2002-03-12 09:05:01 UTC
I was just trying out glib 2.0.0. It compiled fine on SunOS, but three of
the tests failed, namely testgdate, spawn-test and unicode-encoding, all of
which segfaulted. It turned out that in all cases the reason was the same:

  • #0 __icv_iconv
  • #1 iconv
  • #2 g_iconv
    at gconvert.c line 166
  • #3 open_converter
    at gconvert.c line 361
  • #4 g_convert
    at gconvert.c line 491

I tried out the system iconv just by itself, and indeed, calling it with
four null arguments always segfaults. I'm not sure whether this is properly
a bug in Sun's iconv implementation, since at a quick glance I don't see
Unix98 specifying the behavior with all null arguments, so it might be just
an extension in GNU libiconv. In any case, glib probably ought to have a
workaround.
Comment 1 Owen Taylor 2002-03-12 15:41:38 UTC
From Unix98:

For state-dependent encodings, the conversion descriptor cd is placed
into its initial shift state by a call for which inbuf is a null
pointer, or for which inbuf points to a null pointer. When iconv() is
called in this way, and if outbuf is not a null pointer or a pointer
to a null pointer, and outbytesleft points to a positive value,
iconv() will place, into the output buffer, the byte sequence to
change the output buffer to its initial shift state. If the output
buffer is not large enough to hold the entire reset sequence, iconv()
will fail and set errno to [E2BIG]. Subsequent calls with inbuf as
other than a null pointer or a pointer to a null pointer cause the
conversion to take place from the current state of the conversion
descriptor.

So, inbuf and outbuf being NULL is 100% specified behavior. 
Does Solaris iconv behave correctly if you pass in non-NULL for
inbytesleft / outbytesleft?
Comment 2 Lauri Alanko 2002-03-12 16:15:48 UTC
It seems to segfault if anything besides inbuf is NULL. Outbuf, on the
other hand, may _point_ to NULL, but may not _be_ NULL.

Yes, I read the same paragraph from Unix98, and I noted that it
specifically only states what happens "if outbuf is not a null pointer
or a pointer to a null pointer". But I do believe that the intention
is that a null pointer is also allowed. Then again, it's hardly a
wonder if this Sun iconv is not Unix98 compliant, since:

/*
 * Copyright (c) 1993 by Sun Microsystems, Inc.
 */

#ifndef _ICONV_H
#define _ICONV_H

#pragma ident   "@(#)iconv.h    1.2     94/01/21 SMI"


Even the function declaration is wrong:


extern size_t   iconv(iconv_t, const char **, size_t *, char **,
size_t *);


(Since const char** is not compatible with char**)

Anyway. This is probably just a problem with a legacy platform, but it
would be nice if glib worked out of the box here, too. On the other
hand, it took me less effort to install gnu libiconv than to file this
report, so this is not _that_ bad a showstopper. :)
Comment 3 Lauri Alanko 2002-03-13 10:26:53 UTC
I should add that on a Solaris 8 system that I tried, iconv() worked
fine with NULL arguments. So the issue seems to be Solaris 7 -specific.
Comment 4 Owen Taylor 2002-03-20 23:24:45 UTC
Wed Mar 20 18:20:21 2002  Owen Taylor  <otaylor@redhat.com>

        * glib/gconvert.c (open_converter): Try to work around segfaults
        on Solaris if NULL is passed for outbuf... supposedly gchar
        *outbuf = NULL... &outbuf works. (#74336, Lauri Alanko)