mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
pq_getstr didn't handle buffer overrun correctly; it would
fail to consume the rest of the input string, and worse it would write one more byte than it should into the buffer, probably resulting in coredump. Fortunately there's a correct implementation next door in pqcomprim.c.
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.57 1998/10/13 20:44:40 scrappy Exp $
|
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.58 1998/11/29 01:47:42 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -108,6 +108,9 @@ pq_init(int fd)
|
|||||||
*
|
*
|
||||||
* used for debugging libpq
|
* used for debugging libpq
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if 0 /* not used anymore */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pq_getc(FILE *fin)
|
pq_getc(FILE *fin)
|
||||||
{
|
{
|
||||||
@ -119,6 +122,8 @@ pq_getc(FILE *fin)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* --------------------------------
|
/* --------------------------------
|
||||||
* pq_gettty - return the name of the tty in the given buffer
|
* pq_gettty - return the name of the tty in the given buffer
|
||||||
* --------------------------------
|
* --------------------------------
|
||||||
@ -181,15 +186,9 @@ pq_flush()
|
|||||||
int
|
int
|
||||||
pq_getstr(char *s, int maxlen)
|
pq_getstr(char *s, int maxlen)
|
||||||
{
|
{
|
||||||
int c = '\0';
|
int c;
|
||||||
|
|
||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
unsigned char *p,
|
char *p;
|
||||||
*ps;
|
|
||||||
int len;
|
|
||||||
|
|
||||||
ps = s;
|
|
||||||
len = maxlen;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Pfin == (FILE *) NULL)
|
if (Pfin == (FILE *) NULL)
|
||||||
@ -198,27 +197,15 @@ pq_getstr(char *s, int maxlen)
|
|||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (maxlen-- && (c = pq_getc(Pfin)) != EOF && c)
|
c = pqGetString(s, maxlen, Pfin);
|
||||||
*s++ = c;
|
|
||||||
*s = '\0';
|
|
||||||
|
|
||||||
#ifdef MULTIBYTE
|
#ifdef MULTIBYTE
|
||||||
p = pg_client_to_server(ps, len);
|
p = (char*) pg_client_to_server((unsigned char *) s, maxlen);
|
||||||
if (ps != p)
|
if (s != p) /* actual conversion has been done? */
|
||||||
{ /* actual conversion has been done? */
|
strcpy(s, p);
|
||||||
strcpy(ps, p);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -----------------
|
return c;
|
||||||
* If EOF reached let caller know.
|
|
||||||
* (This will only happen if we hit EOF before the string
|
|
||||||
* delimiter is reached.)
|
|
||||||
* -----------------
|
|
||||||
*/
|
|
||||||
if (c == EOF)
|
|
||||||
return EOF;
|
|
||||||
return !EOF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user