8000 Do not use strerror on shared libraries · util-linux/util-linux@1f7a5b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f7a5b3

Browse files
crrodriguezkarelzak
authored andcommitted
Do not use strerror on shared libraries
Using strerror is not safe in shared libraries as it is unknown what the calling apps may do with the storage behind the scenes. Using %m is ok, except in contexts that need to be as-safe. (cherry picked from commit c5850c3)
1 parent 6f3d5e8 commit 1f7a5b3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

libblkid/src/verify.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
7373
diff = (uintmax_t)now - dev->bid_time;
7474

7575
if (stat(dev->bid_name, &st) < 0) {
76-
DBG(PROBE, ul_debug("blkid_verify: error %s (%d) while "
77-
"trying to stat %s", strerror(errno), errno,
76+
DBG(PROBE, ul_debug("blkid_verify: error %m (%d) while "
77+
"trying to stat %s", errno,
7878
dev->bid_name));
7979
open_err:
8080
if ((errno == EPERM) || (errno == EACCES) || (errno == ENOENT)) {
@@ -128,8 +128,8 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
128128

129129
fd = open(dev->bid_name, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
130130
if (fd < 0) {
131-
DBG(PROBE, ul_debug("blkid_verify: error %s (%d) while "
132-
"opening %s", strerror(errno), errno,
131+
DBG(PROBE, ul_debug("blkid_verify: error %m (%d) while "
132+
"opening %s", errno,
133133
dev->bid_name));
134134
goto open_err;
135135
}

liblastlog2/src/lastlog2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ ll2_import_lastlog(struct ll2_context *context, const char *lastlog_file,
559559

560560
ll_fp = fopen(lastlog_file, "r");
561561
if (ll_fp == NULL) {
562-
if (error && asprintf(error, "Failed to open '%s': %s",
563-
lastlog_file, strerror(errno)) < 0)
562+
if (error && asprintf(error, "Failed to open '%s': %m",
563+
lastlog_file) < 0)
564564
return -ENOMEM;
565565

566566
return -1;
@@ -569,8 +569,8 @@ ll2_import_lastlog(struct ll2_context *context, const char *lastlog_file,
569569

570570
if (fstat(fileno(ll_fp), &statll) != 0) {
571571
retval = -1;
572-
if (error && asprintf(error, "Cannot get size of '%s': %s",
573-
lastlog_file, strerror(errno)) < 0)
572+
if (error && asprintf(error, "Cannot get size of '%s': %m",
573+
lastlog_file) < 0)
574574
retval = -ENOMEM;
575575

576576
goto done;

0 commit comments

Comments
 (0)
0