]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: fix double-free
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 12 Dec 2022 05:16:09 +0000 (14:16 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 12 Dec 2022 05:20:47 +0000 (14:20 +0900)
If an attribute is read but the value is not used (i.e. ret_value is NULL),
then sd_device_get_sysattr_value() mistakenly frees the read data even though
it is cached internally.

Fixes a bug introduced by acfc2a1d15560084e077ffb3be472cd117e9020a.

Fixes #25702.

src/libsystemd/sd-device/sd-device.c

index 55a0ee730e89f21a4c9d41f287fd790782681bab..9c4743f05508aa3d2d84aac98a172a04549068c4 100644 (file)
@@ -2332,9 +2332,14 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
                                        sysattr, value, ret_value ? "" : ", ignoring");
                 if (ret_value)
                         return r;
-        } else if (ret_value)
-                *ret_value = TAKE_PTR(value);
 
+                return 0;
+        }
+
+        if (ret_value)
+                *ret_value = value;
+
+        TAKE_PTR(value);
         return 0;
 }