Blame SOURCES/0033-lib-path-make-ul_path_read_buffer-more-robust-coveri.patch
|
|
d8d8bc |
From f6fffc1a89e57b7d5dd4adf1ee6b2146e58ec411 Mon Sep 17 00:00:00 2001
|
|
|
d8d8bc |
From: Karel Zak <kzak@redhat.com>
|
|
|
d8d8bc |
Date: Thu, 17 Mar 2022 12:18:03 +0100
|
|
|
d8d8bc |
Subject: lib/path: make ul_path_read_buffer() more robust [coverity scan]
|
|
|
d8d8bc |
|
|
|
d8d8bc |
Make sure we never call buf[rc - 1] for rc=0.
|
|
|
d8d8bc |
|
|
|
d8d8bc |
Upstream: http://github.com/util-linux/util-linux/commit/ea459dcf95d0bb04c816b71d2b85fbcd8cfc5ee4
|
|
|
d8d8bc |
Addresses: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=2109459
|
|
|
d8d8bc |
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
|
d8d8bc |
---
|
|
|
d8d8bc |
lib/path.c | 17 ++++++++++-------
|
|
|
d8d8bc |
1 file changed, 10 insertions(+), 7 deletions(-)
|
|
|
d8d8bc |
|
|
|
d8d8bc |
diff --git a/lib/path.c b/lib/path.c
|
|
|
d8d8bc |
index 21f9bd1c4..ab034e110 100644
|
|
|
d8d8bc |
--- a/lib/path.c
|
|
|
d8d8bc |
+++ b/lib/path.c
|
|
|
d8d8bc |
@@ -666,14 +666,17 @@ int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...)
|
|
|
d8d8bc |
int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path)
|
|
|
d8d8bc |
{
|
|
|
d8d8bc |
int rc = ul_path_read(pc, buf, bufsz - 1, path);
|
|
|
d8d8bc |
- if (rc < 0)
|
|
|
d8d8bc |
- return rc;
|
|
|
d8d8bc |
|
|
|
d8d8bc |
- /* Remove tailing newline (usual in sysfs) */
|
|
|
d8d8bc |
- if (rc > 0 && *(buf + rc - 1) == '\n')
|
|
|
d8d8bc |
- buf[--rc] = '\0';
|
|
|
d8d8bc |
- else
|
|
|
d8d8bc |
- buf[rc - 1] = '\0';
|
|
|
d8d8bc |
+ if (rc == 0)
|
|
|
d8d8bc |
+ buf[0] = '\0';
|
|
|
d8d8bc |
+
|
|
|
d8d8bc |
+ else if (rc > 0) {
|
|
|
d8d8bc |
+ /* Remove tailing newline (usual in sysfs) */
|
|
|
d8d8bc |
+ if (*(buf + rc - 1) == '\n')
|
|
|
d8d8bc |
+ buf[--rc] = '\0';
|
|
|
d8d8bc |
+ else
|
|
|
d8d8bc |
+ buf[rc - 1] = '\0';
|
|
|
d8d8bc |
+ }
|
|
|
d8d8bc |
|
|
|
d8d8bc |
return rc;
|
|
|
d8d8bc |
}
|
|
|
d8d8bc |
--
|
|
|
d8d8bc |
2.36.1
|
|
|
d8d8bc |
|