From: Tom Lane Date: Wed, 3 Mar 2010 20:31:50 +0000 (+0000) Subject: Fix a couple of places that would loop forever if attempts to read a stdio file X-Git-Tag: REL7_4_28~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f82e8e7f6ff066ca019ed9a2cab1d78bd43738c6;p=postgresql Fix a couple of places that would loop forever if attempts to read a stdio file set ferror() but never set feof(). This is known to be the case for recent glibc when trying to read a directory as a file, and might be true for other platforms/cases too. Per report from Ed L. (There is more that we ought to do about his report, but this is one easily identifiable issue.) --- diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index ba371f728d..497a67ab81 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.213.2.3 2006/05/21 20:06:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.213.2.4 2010/03/03 20:31:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -381,7 +381,7 @@ CopyGetData(void *databuf, int datasize) { case COPY_FILE: fread(databuf, datasize, 1, copy_file); - if (feof(copy_file)) + if (feof(copy_file) || ferror(copy_file)) fe_eof = true; break; case COPY_OLD_FE: diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c index 12c94a3db4..89368aea21 100644 --- a/src/backend/libpq/hba.c +++ b/src/backend/libpq/hba.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.116.2.4 2004/11/17 19:54:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.116.2.5 2010/03/03 20:31:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -317,7 +317,7 @@ tokenize_file(FILE *file) int line_number = 1; char *buf; - while (!feof(file)) + while (!feof(file) && !ferror(file)) { buf = next_token_expand(file); diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 0ff901639a..5ff0fc68c2 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.263.2.6 2007/07/23 18:10:13 mha Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.263.2.7 2010/03/03 20:31:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -3159,7 +3159,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username) if (fp == NULL) return NULL; - while (!feof(fp)) + while (!feof(fp) && !ferror(fp)) { char *t = buf, *ret;