Search Postgresql Archives

Re: Some encoding trouble via libpq

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

 



"Billy Gray" <billy.zophar@xxxxxxxxx> 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux