]> 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:16 +0000 (20:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Mar 2010 20:31:16 +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 d5f44bb49f61ec141c1f8e1221a4002d5140b8d3..847687a05a6ac895a35403a1f8607d25dea432d7 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.188.2.1 2009/10/03 20:04:45 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.188.2.2 2010/03/03 20:31:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -404,7 +404,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 d20d0b601063efb032997ef7aaa3b4e3445e4fbd..4a07bafe6d839050e023705bf9af1453c4eec687 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.375 2009/06/11 14:49:13 momjian Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.375.2.1 2010/03/03 20:31:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3891,7 +3891,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;