Fix a couple of places that would loop forever if attempts to read a stdio file
authorTom Lane
Wed, 3 Mar 2010 20:31:09 +0000 (20:31 +0000)
committerTom Lane
Wed, 3 Mar 2010 20:31:09 +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 79dc90b337b2f82bd1be4dca4edd6a1b0c2907eb..afc39f45bfe676dd75fdf51d1641ae18a9c2b4e6 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.199 2010/03/01 16:02:01 mha Exp $
+ *   $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.200 2010/03/03 20:31:08 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 9302e287822e6007e699842b32f62bfeb65b3916..1dc52ef14856a077b1e4982b50bcfb1f3cc69fd2 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.388 2010/02/26 02:01:32 momjian Exp $
+ *   $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.389 2010/03/03 20:31:09 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -4394,7 +4394,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;