Skip to content

Commit f7c4f98

Browse files
committed
Fix errno handling in filehash and filehash58 probes
1 parent d19b89b commit f7c4f98

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/OVAL/probes/independent/filehash58_probe.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ static int filehash58_cb(const char *prefix, const char *p, const char *f, const
168168
}
169169

170170
if (fd < 0) {
171-
strerror_r (errno, pbuf, PATH_MAX);
172-
pbuf[PATH_MAX] = '\0';
171+
#define __ERRBUF_SIZE 128
172+
char errbuf[__ERRBUF_SIZE] = {0};
173+
oscap_strerror_r(errno, errbuf, sizeof errbuf - 1);
173174

174175
itm = probe_item_create (OVAL_INDEPENDENT_FILE_HASH58, NULL,
175176
"filepath", OVAL_DATATYPE_STRING, pbuf,
@@ -178,7 +179,7 @@ static int filehash58_cb(const char *prefix, const char *p, const char *f, const
178179
"hash_type",OVAL_DATATYPE_STRING, h,
179180
NULL);
180181
probe_item_add_msg(itm, OVAL_MESSAGE_LEVEL_ERROR,
181-
"Can't open \"%s\": errno=%d, %s.", pbuf, errno, strerror (errno));
182+
"Can't open \"%s\": %s (errno=%d).", pbuf, errbuf, errno);
182183
probe_item_setstatus(itm, SYSCHAR_STATUS_ERROR);
183184

184185
probe_item_collect(ctx, itm);

src/OVAL/probes/independent/filehash_probe.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ static int filehash_cb (const char *prefix, const char *p, const char *f, probe_
121121
}
122122

123123
if (fd < 0) {
124-
strerror_r (errno, pbuf, PATH_MAX);
125-
pbuf[PATH_MAX] = '\0';
124+
#define __ERRBUF_SIZE 128
125+
char errbuf[__ERRBUF_SIZE] = {0};
126+
oscap_strerror_r(errno, errbuf, sizeof errbuf - 1);
126127

127128
itm = probe_item_create(OVAL_INDEPENDENT_FILE_HASH, NULL,
128129
"filepath", OVAL_DATATYPE_STRING, include_filepath ? pbuf : NULL,
@@ -131,7 +132,7 @@ static int filehash_cb (const char *prefix, const char *p, const char *f, probe_
131132
NULL
132133
);
133134
probe_item_add_msg(itm, OVAL_MESSAGE_LEVEL_ERROR,
134-
"Can't open \"%s\": errno=%d, %s.", pbuf, errno, strerror (errno));
135+
"Can't open \"%s\": %s (errno=%d).", pbuf, errbuf, errno);
135136
probe_item_setstatus(itm, SYSCHAR_STATUS_ERROR);
136137

137138
} else {

0 commit comments

Comments
 (0)