1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Normalize fgets() calls to use sizeof() for calculating the buffer size

where possible, and fix some sites that apparently thought that fgets()
will overwrite the buffer by one byte.

Also add some strlcpy() to eliminate some weird memory handling.
This commit is contained in:
Peter Eisentraut
2007-02-08 11:10:27 +00:00
parent b79575ce45
commit 086c189456
10 changed files with 38 additions and 41 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.341 2007/01/05 22:20:00 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.342 2007/02/08 11:10:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -2845,11 +2845,11 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
return 1;
}
while ((line = fgets(buf, MAXBUFSIZE - 1, f)) != NULL)
while ((line = fgets(buf, sizeof(buf), f)) != NULL)
{
linenr++;
if (strlen(line) >= MAXBUFSIZE - 2)
if (strlen(line) >= sizeof(buf) - 1)
{
fclose(f);
printfPQExpBuffer(errorMessage,
@ -3654,7 +3654,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
*ret;
int len;
fgets(buf, LINELEN - 1, fp);
fgets(buf, sizeof(buf), fp);
len = strlen(buf);
if (len == 0)

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.91 2007/01/26 17:45:41 neilc Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.92 2007/02/08 11:10:27 petere Exp $
*
* NOTES
* [ Most of these notes are wrong/obsolete, but perhaps not all ]
@ -1018,8 +1018,7 @@ SSLerrmessage(void)
errreason = ERR_reason_error_string(errcode);
if (errreason != NULL)
{
strncpy(errbuf, errreason, SSL_ERR_LEN - 1);
errbuf[SSL_ERR_LEN - 1] = '\0';
strlcpy(errbuf, errreason, SSL_ERR_LEN);
return errbuf;
}
snprintf(errbuf, SSL_ERR_LEN, libpq_gettext("SSL error code %lu"), errcode);