From f749b4ca9cb9045b3e893b04731a81a06fb45bbf Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon, 27 Nov 2000 03:43:49 +0000
Subject: [PATCH] Pay attention to fgets() failure return.

---
 src/backend/libpq/password.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/backend/libpq/password.c b/src/backend/libpq/password.c
index 1eede3799ab..e42b077ed2f 100644
--- a/src/backend/libpq/password.c
+++ b/src/backend/libpq/password.c
@@ -2,7 +2,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: password.c,v 1.32 2000/08/27 21:50:18 tgl Exp $
+ * $Id: password.c,v 1.33 2000/11/27 03:43:49 tgl Exp $
  *
  */
 
@@ -56,9 +56,11 @@ verify_password(const Port *port, const char *user, const char *password)
 				   *test_user,
 				   *test_pw;
 
-		fgets(pw_file_line, sizeof(pw_file_line), pw_file);
+		if (fgets(pw_file_line, sizeof(pw_file_line), pw_file) == NULL)
+			pw_file_line[0] = '\0';
 		/* kill the newline */
-		if (pw_file_line[strlen(pw_file_line) - 1] == '\n')
+		if (strlen(pw_file_line) > 0 &&
+			pw_file_line[strlen(pw_file_line) - 1] == '\n')
 			pw_file_line[strlen(pw_file_line) - 1] = '\0';
 
 		p = pw_file_line;
-- 
GitLab