]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: fix use-of-uninitialized-value or null dereference
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Apr 2019 05:26:23 +0000 (14:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Apr 2019 09:18:11 +0000 (18:18 +0900)
This fixes a bug introduced by 6ef5c881dd5568f08dc35013e24f7d857f36b207.

Fixes oss-fuzz#14157 and oss-fuzz#14158.

src/network/netdev/wireguard.c
test/fuzz/fuzz-netdev-parser/oss-fuzz-14157 [new file with mode: 0644]
test/fuzz/fuzz-netdev-parser/oss-fuzz-14158 [new file with mode: 0644]

index 5aa10fc4dea197addeb1759d4761c74d654563e4..7959c1c01f45f5ca0eeaac50fad6e33b36ae2643 100644 (file)
@@ -498,24 +498,18 @@ static int wireguard_decode_key_and_warn(
                 (void) warn_file_is_world_accessible(filename, NULL, unit, line);
 
         r = unbase64mem_full(rvalue, strlen(rvalue), true, &key, &len);
-        if (r < 0) {
-                log_syntax(unit, LOG_ERR, filename, line, r,
+        if (r < 0)
+                return log_syntax(unit, LOG_ERR, filename, line, r,
                            "Failed to decode wireguard key provided by %s=, ignoring assignment: %m", lvalue);
-                goto finalize;
-        }
         if (len != WG_KEY_LEN) {
-                log_syntax(unit, LOG_ERR, filename, line, 0,
+                explicit_bzero_safe(key, len);
+                return log_syntax(unit, LOG_ERR, filename, line, 0,
                            "Wireguard key provided by %s= has invalid length (%zu bytes), ignoring assignment.",
                            lvalue, len);
-                goto finalize;
         }
 
         memcpy(ret, key, WG_KEY_LEN);
-        r = 0;
-
-finalize:
-        explicit_bzero_safe(key, len);
-        return r;
+        return 0;
 }
 
 int config_parse_wireguard_private_key(
diff --git a/test/fuzz/fuzz-netdev-parser/oss-fuzz-14157 b/test/fuzz/fuzz-netdev-parser/oss-fuzz-14157
new file mode 100644 (file)
index 0000000..d3a65e1
--- /dev/null
@@ -0,0 +1,5 @@
+[NetDev]
+Name=w
+Kind=wireguard
+[WireGuardPeer]
+PublicKey=e
\ No newline at end of file
diff --git a/test/fuzz/fuzz-netdev-parser/oss-fuzz-14158 b/test/fuzz/fuzz-netdev-parser/oss-fuzz-14158
new file mode 100644 (file)
index 0000000..6f6bf72
--- /dev/null
@@ -0,0 +1,5 @@
+[NetDev]
+Name=w
+Kind=wireguard
+[WireGuard]
+PrivateKey=E
\ No newline at end of file