system: fix issues reported by Coverity
[project/procd.git] / system.c
index bd3f76c49583aa2d807b7c0676a2711a0b996839..c208e3ee47434d3433aaa6ead4d3f75df803c6fc 100644 (file)
--- 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);