From: yumkam@gmail.com (Yuriy M. Kaminskiy)
To: util-linux@vger.kernel.org
Subject: [PATCH 2/3] lib/sysfs.c sys-utils/lsns.c: fix error return
Date: Sat, 27 Feb 2016 19:14:44 +0300 [thread overview]
Message-ID: <m3mvqmm8p7.fsf@gmail.com> (raw)
In-Reply-To: m3r3fymc4d.fsf@gmail.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/x-diff, Size: 1252 bytes --]
>From a2c1a0e50581b4b8ff315d052f3b5f1654c024f8 Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Date: Sat, 27 Feb 2016 19:02:49 +0300
Subject: [PATCH 2/3] lib/sysfs.c sys-utils/lsns.c: fix error return
If non-negative value returned, errno could be unset (especially 0).
---
Note: likely impossible to trigger, so this only fixes "formal correctness"
lib/sysfs.c | 2 +-
sys-utils/lsns.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 53aba3a..9d76148 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -464,7 +464,7 @@ int sysfs_write_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t num)
len = snprintf(buf, sizeof(buf), "%" PRIu64, num);
if (len < 0 || (size_t) len + 1 > sizeof(buf))
- rc = -errno;
+ rc = len < 0 ? -errno : -E2BIG;
else
rc = write_all(fd, buf, len);
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 7b8f17d..3bfc6ac 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -255,7 +255,7 @@ static int read_process(struct lsns *ls, pid_t pid)
}
rc = fscanf(f, "%d %*s %c %d*[^\n]", &p->pid, &p->state, &p->ppid);
if (rc != 3) {
- rc = -errno;
+ rc = rc < 0 ? -errno : -EINVAL;
goto done;
}
rc = 0;
--
2.1.4
next prev parent reply other threads:[~2016-02-27 16:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-27 15:00 [PATCH] lscpu: fix backward buffer size adjustment after adding delimiter Yuriy M. Kaminskiy
2016-02-27 16:14 ` Yuriy M. Kaminskiy [this message]
2016-02-27 16:27 ` [PATCH 3/3] snprintf: safer (and uniform) handling of return value Yuriy M. Kaminskiy
2016-03-07 12:43 ` Karel Zak
2016-03-07 14:16 ` [PATCH] lscpu: fix backward buffer size adjustment after adding delimiter Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3mvqmm8p7.fsf@gmail.com \
--to=yumkam@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox