Skip to content

Commit 0954358

Browse files
committed
Fix a couple of places where the result of fgets() wasn't checked.
This is mostly to suppress compiler warnings, although in principle the cases could result in undesirable behavior. Martin Pitt
1 parent 21992dd commit 0954358

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/bin/psql/prompt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.53 2010/01/02 16:57:59 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.54 2010/04/30 17:09:13 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -252,7 +252,8 @@ get_prompt(promptStatus_t status)
252252
fd = popen(file, "r");
253253
if (fd)
254254
{
255-
fgets(buf, sizeof(buf), fd);
255+
if (fgets(buf, sizeof(buf), fd) == NULL)
256+
buf[0] = '\0';
256257
pclose(fd);
257258
}
258259
if (strlen(buf) > 0 && buf[strlen(buf) - 1] == '\n')

src/interfaces/libpq/fe-connect.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.391 2010/03/17 20:58:38 petere Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.392 2010/04/30 17:09:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4400,7 +4400,8 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
44004400
*ret;
44014401
int len;
44024402

4403-
fgets(buf, sizeof(buf), fp);
4403+
if (fgets(buf, sizeof(buf), fp) == NULL)
4404+
break;
44044405

44054406
len = strlen(buf);
44064407
if (len == 0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy