diff options
| author | Peter Eisentraut | 2007-02-08 11:10:27 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2007-02-08 11:10:27 +0000 |
| commit | 086c189456655846707d9a260a3919f4404ecd9e (patch) | |
| tree | c4c34d96579d19884bdc12cec5dec76f6a8f962c /src/interfaces | |
| parent | b79575ce4599db628a09773003b2e73d81d75f54 (diff) | |
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.
Diffstat (limited to 'src/interfaces')
| -rw-r--r-- | src/interfaces/libpq/fe-connect.c | 8 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-secure.c | 5 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index cc0c6613c4..891bf3f9ac 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -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) diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c index a471c0b11f..2d387b19d2 100644 --- a/src/interfaces/libpq/fe-secure.c +++ b/src/interfaces/libpq/fe-secure.c @@ -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); |
