mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
Check return value of pclose() correctly
Some callers didn't check the return value of pclose() or ClosePipeStream() correctly. Either they didn't check it at all or they treated it like the return of fclose(). The correct way is to first check whether the return value is -1, and then report errno, and then check the return value like a result from system(), for which we already have wait_result_to_str() to make it simpler. To make this more compact, expand wait_result_to_str() to also handle -1 explicitly. Reviewed-by: Ankit Kumar Pandey <itsankitkp@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/8cd9fb02-bc26-65f1-a809-b1cb360eef73@enterprisedb.com
This commit is contained in:
@ -2731,14 +2731,24 @@ exec_command_write(PsqlScanState scan_state, bool active_branch,
|
||||
fprintf(fd, "%s\n", previous_buf->data);
|
||||
|
||||
if (is_pipe)
|
||||
{
|
||||
result = pclose(fd);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
pg_log_error("%s: %s", fname, wait_result_to_str(result));
|
||||
status = PSQL_CMD_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = fclose(fd);
|
||||
|
||||
if (result == EOF)
|
||||
{
|
||||
pg_log_error("%s: %m", fname);
|
||||
status = PSQL_CMD_ERROR;
|
||||
if (result == EOF)
|
||||
{
|
||||
pg_log_error("%s: %m", fname);
|
||||
status = PSQL_CMD_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user