From 040fecc1c14f812c0f8bdc3426366539ad88fe64 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sun, 15 Aug 2021 11:52:20 +0100 Subject: [PATCH] system: fix issues reported by Coverity Coverity CID: 1490346 Buffer not null terminated Coverity CID: 1490345 Dereference null return value Fixes: 9f233f5 ("system: make rootfs type accessible through board call") Signed-off-by: Daniel Golle --- system.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/system.c b/system.c index bd3f76c..c208e3e 100644 --- a/system.c +++ b/system.c @@ -60,6 +60,9 @@ static const char *system_rootfs_type(void) { return fstype; mounts = fopen(proc_mounts, "r"); + if (!mounts) + return NULL; + while ((nread = getline(&mountstr, &len, mounts)) != -1) { found = false; @@ -101,8 +104,9 @@ static const char *system_rootfs_type(void) { } if (found) - strncpy(fstype, tmp, sizeof(fstype)); + strncpy(fstype, tmp, sizeof(fstype) - 1); + fstype[sizeof(fstype) - 1]= '\0'; free(mountstr); fclose(mounts); -- 2.30.2