]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Be more defensive when parsing PRETTY_NAME out of os-release
authorEnji Cooper <yaneurabeya@gmail.com>
Thu, 6 Jun 2024 04:25:59 +0000 (21:25 -0700)
committerVincent Bernat <vincent@bernat.ch>
Thu, 6 Jun 2024 06:53:16 +0000 (08:53 +0200)
Test the result of `strtok(..)` to ensure that the line being parsed has
an `=` sign in it. This addresses a potential crash due to a NULL
pointer dereference.

Reported by: Coverity
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
src/daemon/lldpd.c

index dc68f19f3d40a1b6266427fd6774e456a78e21cf..6b5721e2e336dda47d36332e98cb45e358d6587a 100644 (file)
@@ -859,6 +859,8 @@ lldpd_get_os_release()
 
        while ((fgets(line, sizeof(line), fp) != NULL)) {
                key = strtok(line, "=");
+               if (key == NULL) continue;
+
                val = strtok(NULL, "=");
 
                if (strncmp(key, "PRETTY_NAME", sizeof(line)) == 0) {