Re: memory scribbling while using IOChannels



> From: "Matthias Clasen" <matthiasc poet de>
>
> It looks at least suspicious that  g_iochannel_fill_buffer holds a reference
> to channel->encoded_read_buf->str
> over the g_string_set_size call, because g_string_set_size may end up
> reallocating that pointer (in g_string_maybe_expand).
>
> The following patch seems to fix your test case.
>
> Matthias
>
>
>
> Index: glib/giochannel.c
> ===================================================================
> RCS file: /cvs/gnome/glib/glib/giochannel.c,v
> retrieving revision 1.23
> diff -u -3 -p -u -r1.23 giochannel.c
> --- glib/giochannel.c 2001/08/16 23:02:52 1.23
> +++ glib/giochannel.c 2001/08/24 08:43:30
> @@ -1212,15 +1212,17 @@ reencode:
>                             - channel->encoded_read_buf->len));
>
>        inbuf = channel->read_buf->str;
> -      outbuf = channel->encoded_read_buf->str +
> channel->encoded_read_buf->len;
>
>        g_string_set_size (channel->encoded_read_buf,
>                           channel->encoded_read_buf->len + outbytes_left);
>
> +      outbuf = channel->encoded_read_buf->str +
> channel->encoded_read_buf->len - outbytes_left;
> +
>        errnum = g_iconv (channel->read_cd, &inbuf, &inbytes_left,
>     &outbuf, &outbytes_left);
> -      errval = errno;
>
> +      errval = errno;
> +
>        g_assert (inbuf + inbytes_left == channel->read_buf->str
>                  + channel->read_buf->len);
>        g_assert (outbuf + outbytes_left == channel->encoded_read_buf->str

Thanks for catching this. There's also a similar bug in g_io_channel_write_chars().
If you haven't committed yet, I'd be happy to do so.

Ron Steinke




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]