[Libguestfs] [PATCH 2/2] lib: utf16: Fix const-correctness issues in _hivex_recode function.

Richard W.M. Jones rjones at redhat.com
Mon Jan 6 11:11:37 UTC 2014


On Mon, Jan 06, 2014 at 11:31:18AM +0100, Pino Toscano wrote:
> On Tuesday 31 December 2013 14:27:11 Richard W.M. Jones wrote:
> > This patch assumes that iconv doesn't actually modify the
> > input buffer, even though it is declared as char *.
> > ---
> > [...]
> > @@ -51,10 +51,11 @@ _hivex_recode (char *input_encoding, const char
> > *input, size_t input_len, errno = err;
> >      return NULL;
> >    }
> > -  char *inp = input;
> > +  const char *inp = input;
> >    char *outp = out;
> > 
> > -  size_t r = iconv (ic, &inp, &inlen, &outp, &outlen);
> > +  /* Surely iconv doesn't really modify the input buffer? XXX */
> > +  size_t r = iconv (ic, (char **) &inp, &inlen, &outp, &outlen);
> >    if (r == (size_t) -1) {
> 
> This (the constness of the input argument) is the difference between the 
> iconv implementation provided in GNU libc and the other ones, even 
> though it reflects POSIX [1].

I found there's an "entertaining" bug about this:

https://sourceware.org/bugzilla/show_bug.cgi?id=2962

> The iconv.m4 module in gnulib checks for this too, and AC_DEFINE's 
> ICONV_CONST as "const" (or empty) depending on the actual prototype of 
> iconv(3).
> 
> [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/iconv.html

I committed this patch [with the (char **) cast].  Using gnulib's
ICONV_CONST is possible, although I suppose it wouldn't make much
difference to us.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW




More information about the Libguestfs mailing list