summaryrefslogtreecommitdiffstats
path: root/term-utils/ttymsg.c
diff options
context:
space:
mode:
authorYuriy M. Kaminskiy2016-02-27 17:27:29 +0100
committerKarel Zak2016-03-07 15:11:06 +0100
commit06fa5817489adb9728f8a29d4cb7602fb48b8bdb (patch)
treeb3a6f1d0db6b1a6d0e340c1297f243c07c1de618 /term-utils/ttymsg.c
parentlsns.c: fix error return (diff)
downloadkernel-qcow2-util-linux-06fa5817489adb9728f8a29d4cb7602fb48b8bdb.tar.gz
kernel-qcow2-util-linux-06fa5817489adb9728f8a29d4cb7602fb48b8bdb.tar.xz
kernel-qcow2-util-linux-06fa5817489adb9728f8a29d4cb7602fb48b8bdb.zip
misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'term-utils/ttymsg.c')
-rw-r--r--term-utils/ttymsg.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/term-utils/ttymsg.c b/term-utils/ttymsg.c
index 18a723f86..2aab69f10 100644
--- a/term-utils/ttymsg.c
+++ b/term-utils/ttymsg.c
@@ -90,7 +90,7 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
also wrong since people use /dev/pts/xxx. */
len = snprintf(device, sizeof(device), "%s%s", _PATH_DEV, line);
- if (len < 0 || len + 1 > (ssize_t) sizeof(device)) {
+ if (len < 0 || (size_t)len >= sizeof(device)) {
snprintf(errbuf, sizeof(errbuf), _("excessively long line arg"));
return errbuf;
}
@@ -104,7 +104,7 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
return NULL;
len = snprintf(errbuf, sizeof(errbuf), "%s: %m", device);
- if (len < 0 || len + 1 > (ssize_t) sizeof(errbuf))
+ if (len < 0 || (size_t)len >= sizeof(errbuf))
snprintf(errbuf, sizeof(errbuf), _("open failed"));
return errbuf;
}
@@ -145,7 +145,7 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
cpid = fork();
if (cpid < 0) {
len = snprintf(errbuf, sizeof(errbuf), _("fork: %m"));
- if (len < 0 || len + 1 > (ssize_t) sizeof(errbuf))
+ if (len < 0 || (size_t)len >= sizeof(errbuf))
snprintf(errbuf, sizeof(errbuf), _("cannot fork"));
close(fd);
return errbuf;
@@ -177,7 +177,7 @@ ttymsg(struct iovec *iov, size_t iovcnt, char *line, int tmout) {
_exit(EXIT_FAILURE);
len = snprintf(errbuf, sizeof(errbuf), "%s: %m", device);
- if (len < 0 || len + 1 > (ssize_t) sizeof(errbuf))
+ if (len < 0 || (size_t)len >= sizeof(errbuf))
snprintf(errbuf, sizeof(errbuf),
_("%s: BAD ERROR, message is "
"far too long"), device);