Fix a couple of places that would loop forever if attempts to read a stdio file
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Mar 2010 20:31:29 +0000 (20:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Mar 2010 20:31:29 +0000 (20:31 +0000)
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.)

src/backend/libpq/hba.c
src/interfaces/libpq/fe-connect.c

index cfacd208c6b29cf78cdd8253e7aaa1a99b9061b3..20470454c66cd692d36dc741e77a1bd44ce13ff2 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.157 2006/11/05 22:42:08 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.157.2.1 2010/03/03 20:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -412,7 +412,7 @@ tokenize_file(const char *filename, FILE *file,
 
    *lines = *line_nums = NIL;
 
-   while (!feof(file))
+   while (!feof(file) && !ferror(file))
    {
        buf = next_token_expand(filename, file);
 
index 4a0f86cbf0f085a50dc8bd0bb7d1e058cfc5e27d..5412ee606ffc9bf24905d62c37b5979b11de3e3b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.339.2.3 2007/10/09 15:03:31 mha Exp $
+ *   $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.339.2.4 2010/03/03 20:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3637,7 +3637,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;