]> git.ipfire.org Git - thirdparty/postgresql.git/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:34 +0000 (20:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 3 Mar 2010 20:31:34 +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 b720953608573b9c5251b19c35a8ff91074df5e8..a8f1bd36067dccfe3109ed3292cdfbf9f6bf3996 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.149 2005/10/17 16:24:19 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.149.2.1 2010/03/03 20:31:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -413,7 +413,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 51e312d5e0bfd5099af36d1eca5bb8138954881e..9fd782e6013c8ed16fe79551e23fd856b667d3b8 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.323.2.4 2007/10/09 15:03:30 mha Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.323.2.5 2010/03/03 20:31:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -3146,7 +3146,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;