Re: Some encoding trouble via libpq - Mailing list pgsql-general

From Tom Lane
Subject Re: Some encoding trouble via libpq
Date
Msg-id 29814.1175197572@sss.pgh.pa.us
Whole thread Raw
In response to Some encoding trouble via libpq  ("Billy Gray" <billy.zophar@gmail.com>)
Responses Re: Some encoding trouble via libpq  ("William Gray" <billy.zophar@gmail.com>)
List pgsql-general
"Billy Gray" <billy.zophar@gmail.com> writes:
>     char *buffer = (char *) xmalloc (STDIN_BLOCK); //xmalloc is really
> malloc
>     int offset = 0;
>     int read = 1;
>     int size = STDIN_BLOCK;

>     while ( (read > 0) && (offset <= STDIN_MAX) )
>     {
>         syslog (LOG_DEBUG, "Reading a block...");
>         read = fread (buffer + offset, 1, STDIN_BLOCK, stdin);
>         offset += read;
>         if (read == STDIN_BLOCK)
>         {
>             size += STDIN_BLOCK;
>             buffer = xrealloc (buffer, size);
>         }
>     } // while

This looks to me like it risks telling fread to read more bytes than
will actually fit in the buffer at the moment.  Think about what happens
if fread returns only a partial bufferload on any particular call.
I'm guessing you're clobbering memory ...

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Postgres Crash Running PLPGSQL Function on 8.2.3
Next
From: "Merlin Moncure"
Date:
Subject: Re: cutting out the middleperl