Skip to content

Commit

Permalink
Fix incorrect use of ferror(3) on NULL FILE* in ntsu_socketutil whe…
Browse files Browse the repository at this point in the history
…n parsing the /proc filesystem
  • Loading branch information
lxv authored Sep 17, 2024
1 parent 76b8da6 commit 3f408ef
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions groups/nts/ntsu/ntsu_socketutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4998,7 +4998,7 @@ ntsa::Error reportInfoProcNetTcp(bsl::vector<ntsa::SocketInfo>* result,

FILE* file = bsl::fopen(fileName, "r");
if (file == 0) {
error = ntsa::Error(bsl::ferror(file));
error = ntsa::Error(errno);
BSLS_LOG_ERROR("Failed to open '%s': %s",
fileName,
error.text().c_str());
Expand All @@ -5008,7 +5008,8 @@ ntsa::Error reportInfoProcNetTcp(bsl::vector<ntsa::SocketInfo>* result,
char line[256];

if (bsl::fgets(line, sizeof(line), file) == 0) {
error = ntsa::Error(bsl::ferror(file));
error = bsl::ferror(file) ? ntsa::Error(errno)
: ntsa::Error(ntsa::Error::e_EOF);
BSLS_LOG_ERROR("Failed to read '%s': "
"failed to read header line: %s",
fileName,
Expand Down Expand Up @@ -5061,7 +5062,7 @@ ntsa::Error reportInfoProcNetUdp(bsl::vector<ntsa::SocketInfo>* result,

FILE* file = bsl::fopen(fileName, "r");
if (file == 0) {
error = ntsa::Error(bsl::ferror(file));
error = ntsa::Error(errno);
BSLS_LOG_ERROR("Failed to open '%s': %s",
fileName,
error.text().c_str());
Expand All @@ -5071,7 +5072,8 @@ ntsa::Error reportInfoProcNetUdp(bsl::vector<ntsa::SocketInfo>* result,
char line[256];

if (bsl::fgets(line, sizeof(line), file) == 0) {
error = ntsa::Error(bsl::ferror(file));
error = bsl::ferror(file) ? ntsa::Error(errno)
: ntsa::Error(ntsa::Error::e_EOF);
BSLS_LOG_ERROR("Failed to read '%s': "
"failed to read header line: %s",
fileName,
Expand Down

0 comments on commit 3f408ef

Please sign in to comment.