]> granicus.if.org Git - postgresql/commitdiff
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:22 +0000 (20:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Mar 2010 20:31:22 +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 181e0c67b8d4fc5f476b7dc68ae8f02f26f9b625..b8b5c5eb68ab48db6d183b255e488f41264a3d28 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.164 2008/01/01 19:45:49 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.164.2.1 2010/03/03 20:31:22 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 33cd597eaa05825b8372e7e1ec740b08ab43c447..627b091753af651b10a2a7d2c7fcb8b55df707d4 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.356.2.1 2008/10/23 16:17:22 mha Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.356.2.2 2010/03/03 20:31:22 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3755,7 +3755,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;