Fix a couple of places where the result of fgets() wasn't checked.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 30 Apr 2010 17:09:13 +0000 (17:09 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 30 Apr 2010 17:09:13 +0000 (17:09 +0000)
This is mostly to suppress compiler warnings, although in principle
the cases could result in undesirable behavior.

Martin Pitt

src/bin/psql/prompt.c
src/interfaces/libpq/fe-connect.c

index 487ab2804e50697b367fbf4d9f3e146d1f6220f6..b08234b7814465f9ed3422d99af42a0263c066b1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2010, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.53 2010/01/02 16:57:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.54 2010/04/30 17:09:13 tgl Exp $
  */
 #include "postgres_fe.h"
 
@@ -252,7 +252,8 @@ get_prompt(promptStatus_t status)
                                                fd = popen(file, "r");
                                                if (fd)
                                                {
-                                                       fgets(buf, sizeof(buf), fd);
+                                                       if (fgets(buf, sizeof(buf), fd) == NULL)
+                                                               buf[0] = '\0';
                                                        pclose(fd);
                                                }
                                                if (strlen(buf) > 0 && buf[strlen(buf) - 1] == '\n')
index e2d1355a3db09794a002d59dd4c082f736cf3743..54db2b7b8962b61c3512d8e04c9230b633d33d2f 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.391 2010/03/17 20:58:38 petere Exp $
+ *       $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.392 2010/04/30 17:09:13 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -4400,7 +4400,8 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
                                   *ret;
                int                     len;
 
-               fgets(buf, sizeof(buf), fp);
+               if (fgets(buf, sizeof(buf), fp) == NULL)
+                       break;
 
                len = strlen(buf);
                if (len == 0)