]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: fix potential invalid memory access
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Aug 2023 20:08:23 +0000 (05:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 9 Aug 2023 20:13:17 +0000 (05:13 +0900)
Follow-up for 28141620d963c0c490d409d6ec6ff5f143357124.

Addresses post-merge review in #28269.

src/udev/udev-builtin-net_id.c

index e82285b5ff22196a49122d0a99ed6af4e2544b92..156802f2965f55baf9fd5d773ffd892cb93983f9 100644 (file)
@@ -702,18 +702,14 @@ static int names_platform(sd_device *dev, const char *prefix, bool test) {
         /* Platform devices are named after ACPI table match, and instance id
          * eg. "/sys/devices/platform/HISI00C2:00"
          * The Vendor (3 or 4 char), followed by hexadecimal model number : instance id. */
-        if (p[7] == ':') {
+        if (r == 10 && p[7] == ':') {
                 /* 3 char vendor string */
-                if (r != 10)
-                        return -EINVAL;
                 vendor = strndupa(p, 3);
                 model_str = strndupa(p + 3, 4);
                 instance_str = strndupa(p + 8, 2);
                 validchars = UPPERCASE_LETTERS;
-        } else if (p[8] == ':') {
+        } else if (r == 11 && p[8] == ':') {
                 /* 4 char vendor string */
-                if (r != 11)
-                        return -EINVAL;
                 vendor = strndupa(p, 4);
                 model_str = strndupa(p + 4, 4);
                 instance_str = strndupa(p + 9, 2);