Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c9f48b5

Browse files
committed
Check the return value of getcwd(), instead of assuming success.
Kevin Grittner
1 parent a030bfa commit c9f48b5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

contrib/pg_upgrade/option.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ parseCommandLine(int argc, char *argv[])
5656
int option; /* Command line option */
5757
int optindex = 0; /* used by getopt_long */
5858
int os_user_effective_id;
59+
char *return_buf;
5960

6061
user_opts.transfer_mode = TRANSFER_MODE_COPY;
6162

@@ -93,7 +94,9 @@ parseCommandLine(int argc, char *argv[])
9394
if (os_user_effective_id == 0)
9495
pg_log(PG_FATAL, "%s: cannot be run as root\n", os_info.progname);
9596

96-
getcwd(os_info.cwd, MAXPGPATH);
97+
return_buf = getcwd(os_info.cwd, MAXPGPATH);
98+
if (return_buf == NULL)
99+
pg_log(PG_FATAL, "Could not access current working directory: %s\n", getErrorText(errno));
97100

98101
while ((option = getopt_long(argc, argv, "d:D:b:B:cgG:kl:o:O:p:P:u:v",
99102
long_options, &optindex)) != -1)

0 commit comments

Comments
 (0)