summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2021-08-31 00:35:53 +0100
committerDaniel Golle <daniel@makrotopia.org>2021-08-31 00:46:49 +0100
commit86f82f3de1da07ef86a33a8e9302c98dafbfa6ec (patch)
treec59c3d75423ca17c5198a1f9b889fb46c0d3418d /utils
parent8eb1d783cca6e0d501dd3a2f94262ffc36ae6482 (diff)
downloadprocd-86f82f3de1da07ef86a33a8e9302c98dafbfa6ec.tar.gz
utils: don't ignore open() return value
In case active console cannot be opened, return NULL early instead of trying to read from errornous file descriptor. Coverity CID: 1490087 Argument cannot be negative Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 2cfcc8e..f0c4a90 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -139,7 +139,12 @@ char *get_active_console(char *out, int len)
{
char line[CMDLINE_SIZE + 1];
int fd = open("/sys/class/tty/console/active", O_RDONLY);
- ssize_t r = read(fd, line, sizeof(line) - 1);
+ ssize_t r;
+
+ if (fd < 0)
+ return NULL;
+
+ r = read(fd, line, sizeof(line) - 1);
line[CMDLINE_SIZE] = '\0';
close(fd);