aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libblkid/src/topology/lvm.c4
-rw-r--r--login-utils/utmpdump.c7
-rw-r--r--sys-utils/hwclock.c16
-rw-r--r--sys-utils/irq-common.c3
-rw-r--r--tests/expected/lsfd/column-kthread10
-rw-r--r--tests/helpers/test_mkfds.c56
-rwxr-xr-xtests/ts/lsfd/column-kthread4
-rwxr-xr-xtests/ts/lsfd/option-pid2
-rwxr-xr-xtests/ts/lsfd/option-summary2
9 files changed, 62 insertions, 42 deletions
diff --git a/libblkid/src/topology/lvm.c b/libblkid/src/topology/lvm.c
index 8b0c0feea9..6ab7a5019e 100644
--- a/libblkid/src/topology/lvm.c
+++ b/libblkid/src/topology/lvm.c
@@ -107,10 +107,10 @@ static int probe_lvm_tp(blkid_probe pr,
while (fgets(buf, sizeof(buf), stream) != NULL) {
if (!strncmp(buf, "Stripes", 7))
- sscanf(buf, "Stripes %d", &stripes);
+ ignore_result( sscanf(buf, "Stripes %d", &stripes) );
if (!strncmp(buf, "Stripe size", 11))
- sscanf(buf, "Stripe size (KByte) %d", &stripesize);
+ ignore_result( sscanf(buf, "Stripe size (KByte) %d", &stripesize) );
}
if (!stripes)
diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c
index 274f0d97aa..a0ff2b170d 100644
--- a/login-utils/utmpdump.c
+++ b/login-utils/utmpdump.c
@@ -282,7 +282,12 @@ static void undump(FILE *in, FILE *out)
while (fgets(linestart, 1023, in)) {
line = linestart;
memset(&ut, '\0', sizeof(ut));
- sscanf(line, "[%hd] [%d] [%4c] ", &ut.ut_type, &ut.ut_pid, ut.ut_id);
+
+ if (sscanf(line, "[%hd] [%d] [%4c] ",
+ &ut.ut_type, &ut.ut_pid, ut.ut_id) != 3) {
+ warnx(_("parse error: %s"), line);
+ continue;
+ }
line += 19;
line += gettok(line, ut.ut_user, sizeof(ut.ut_user), 1);
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index ff148f62ac..af8ac0860c 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -251,15 +251,17 @@ static int read_adjtime(const struct hwclock_control *ctl,
fclose(adjfile);
- sscanf(line1, "%lf %"SCNd64" %lf",
- &adjtime_p->drift_factor,
- &last_adj_time,
- &adjtime_p->not_adjusted);
+ if (sscanf(line1, "%lf %"SCNd64" %lf",
+ &adjtime_p->drift_factor,
+ &last_adj_time,
+ &adjtime_p->not_adjusted) != 3)
+ warnx(_("Warning: unrecognized line in adjtime file: %s"), line1);
- sscanf(line2, "%"SCNd64, &last_calib_time);
+ if (sscanf(line2, "%"SCNd64, &last_calib_time) != 1)
+ warnx(_("Warning: unrecognized line in adjtime file: %s"), line2);
- adjtime_p->last_adj_time = (time_t)last_adj_time;
- adjtime_p->last_calib_time = (time_t)last_calib_time;
+ adjtime_p->last_adj_time = (time_t)last_adj_time;
+ adjtime_p->last_calib_time = (time_t)last_calib_time;
if (!strcmp(line3, "UTC\n")) {
adjtime_p->local_utc = UTC;
diff --git a/sys-utils/irq-common.c b/sys-utils/irq-common.c
index 3506753947..aa10f7e05b 100644
--- a/sys-utils/irq-common.c
+++ b/sys-utils/irq-common.c
@@ -290,7 +290,8 @@ static struct irq_stat *get_irqinfo(int softirq)
for (index = 0; (index < stat->nr_active_cpu) && (tmp - line < length); index++) {
struct irq_cpu *cpu = &stat->cpus[index];
- sscanf(tmp, " %10lu", &count);
+ if (sscanf(tmp, " %10lu", &count) != 1)
+ continue;
curr->total += count;
cpu->total += count;
stat->total_irq += count;
diff --git a/tests/expected/lsfd/column-kthread b/tests/expected/lsfd/column-kthread
index 98b0354763..db81a93cba 100644
--- a/tests/expected/lsfd/column-kthread
+++ b/tests/expected/lsfd/column-kthread
@@ -1,6 +1,6 @@
-COMMAND PID USER MODE TYPE INODE NAME KTHREAD
-systemd 1 root --- DIR 2 / 0
-systemd 1 root --- DIR 2 / 0
-kthreadd 2 root --- DIR 2 / 1
-kthreadd 2 root --- DIR 2 / 1
+COMMAND PID USER MODE TYPE NAME KTHREAD
+systemd 1 root --- DIR / 0
+systemd 1 root --- DIR / 0
+kthreadd 2 root --- DIR / 1
+kthreadd 2 root --- DIR / 1
0
diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c
index aa96ac79c6..db6e92fdb6 100644
--- a/tests/helpers/test_mkfds.c
+++ b/tests/helpers/test_mkfds.c
@@ -245,11 +245,14 @@ static void open_ro_regular_file(const struct factory *factory, struct fdesc fde
}
free_arg(&offset);
- if (dup2(fd, fdescs[0].fd) < 0) {
- int e = errno;
+ if (fd != fdescs[0].fd) {
+ if (dup2(fd, fdescs[0].fd) < 0) {
+ int e = errno;
+ close(fd);
+ errno = e;
+ err(EXIT_FAILURE, "failed to dup %d -> %d", fd, fdescs[0].fd);
+ }
close(fd);
- errno = e;
- err(EXIT_FAILURE, "failed to dup %d -> %d", fd, fdescs[0].fd);
}
fdescs[0] = (struct fdesc){
@@ -302,13 +305,16 @@ static void make_pipe(const struct factory *factory, struct fdesc fdescs[], pid_
}
for (int i = 0; i < 2; i++) {
- if (dup2(pd[i], fdescs[i].fd) < 0) {
- int e = errno;
- close(pd[0]);
- close(pd[1]);
- errno = e;
- err(EXIT_FAILURE, "failed to dup %d -> %d",
- pd[i], fdescs[i].fd);
+ if (pd[i] != fdescs[i].fd) {
+ if (dup2(pd[i], fdescs[i].fd) < 0) {
+ int e = errno;
+ close(pd[0]);
+ close(pd[1]);
+ errno = e;
+ err(EXIT_FAILURE, "failed to dup %d -> %d",
+ pd[i], fdescs[i].fd);
+ }
+ close(pd[i]);
}
fdescs[i] = (struct fdesc){
.fd = fdescs[i].fd,
@@ -339,11 +345,14 @@ static void open_directory(const struct factory *factory, struct fdesc fdescs[],
err(EXIT_FAILURE, "failed to open: %s", ARG_STRING(dir));
free_arg(&dir);
- if (dup2(fd, fdescs[0].fd) < 0) {
- int e = errno;
+ if (fd != fdescs[0].fd) {
+ if (dup2(fd, fdescs[0].fd) < 0) {
+ int e = errno;
+ close(fd);
+ errno = e;
+ err(EXIT_FAILURE, "failed to dup %d -> %d", fd, fdescs[0].fd);
+ }
close(fd);
- errno = e;
- err(EXIT_FAILURE, "failed to dup %d -> %d", fd, fdescs[0].fd);
}
if (ARG_INTEGER(dentries) > 0) {
@@ -412,13 +421,16 @@ static void make_socketpair(const struct factory *factory, struct fdesc fdescs[]
err(EXIT_FAILURE, "failed to make socket pair");
for (int i = 0; i < 2; i++) {
- if (dup2(sd[i], fdescs[i].fd) < 0) {
- int e = errno;
- close(sd[0]);
- close(sd[1]);
- errno = e;
- err(EXIT_FAILURE, "failed to dup %d -> %d",
- sd[i], fdescs[i].fd);
+ if (sd[i] != fdescs[i].fd) {
+ if (dup2(sd[i], fdescs[i].fd) < 0) {
+ int e = errno;
+ close(sd[0]);
+ close(sd[1]);
+ errno = e;
+ err(EXIT_FAILURE, "failed to dup %d -> %d",
+ sd[i], fdescs[i].fd);
+ }
+ close(sd[i]);
}
fdescs[i] = (struct fdesc){
.fd = fdescs[i].fd,
diff --git a/tests/ts/lsfd/column-kthread b/tests/ts/lsfd/column-kthread
index 1cf8fdb8b3..3a1bf78ae5 100755
--- a/tests/ts/lsfd/column-kthread
+++ b/tests/ts/lsfd/column-kthread
@@ -16,7 +16,7 @@
#
TS_TOPDIR="${0%/*}/../.."
-TS_DESC="directory"
+TS_DESC="kthread column"
. $TS_TOPDIR/functions.sh
ts_init "$*"
@@ -32,7 +32,7 @@ ts_skip_nonroot
ts_cd "$TS_OUTDIR"
{
- "$TS_CMD_LSFD" -o COMMAND,PID,USER,MODE,TYPE,INODE,NAME,KTHREAD \
+ "$TS_CMD_LSFD" -o COMMAND,PID,USER,MODE,TYPE,NAME,KTHREAD \
-Q '(PID < 3) and ((ASSOC == "cwd") or (ASSOC == "rtd"))'
echo $?
} > $TS_OUTPUT 2>&1
diff --git a/tests/ts/lsfd/option-pid b/tests/ts/lsfd/option-pid
index 7882dc1b0d..5bd6b63662 100755
--- a/tests/ts/lsfd/option-pid
+++ b/tests/ts/lsfd/option-pid
@@ -15,7 +15,7 @@
# GNU General Public License for more details.
#
TS_TOPDIR="${0%/*}/../.."
-TS_DESC="directory"
+TS_DESC="--pid option"
. $TS_TOPDIR/functions.sh
ts_init "$*"
diff --git a/tests/ts/lsfd/option-summary b/tests/ts/lsfd/option-summary
index 466e3d80b8..e27122aea7 100755
--- a/tests/ts/lsfd/option-summary
+++ b/tests/ts/lsfd/option-summary
@@ -15,7 +15,7 @@
# GNU General Public License for more details.
#
TS_TOPDIR="${0%/*}/../.."
-TS_DESC="directory"
+TS_DESC="--summary option"
. $TS_TOPDIR/functions.sh
ts_init "$*"