Skip to content

Commit 3f408ef

Browse files
authored
Fix incorrect use of ferror(3) on NULL FILE* in ntsu_socketutil when parsing the /proc filesystem
1 parent 76b8da6 commit 3f408ef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

groups/nts/ntsu/ntsu_socketutil.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -4998,7 +4998,7 @@ ntsa::Error reportInfoProcNetTcp(bsl::vector<ntsa::SocketInfo>* result,
49984998

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

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

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

50735074
if (bsl::fgets(line, sizeof(line), file) == 0) {
5074-
error = ntsa::Error(bsl::ferror(file));
5075+
error = bsl::ferror(file) ? ntsa::Error(errno)
5076+
: ntsa::Error(ntsa::Error::e_EOF);
50755077
BSLS_LOG_ERROR("Failed to read '%s': "
50765078
"failed to read header line: %s",
50775079
fileName,

0 commit comments

Comments
 (0)