From: Yu Watanabe Date: Tue, 26 Feb 2019 03:55:40 +0000 (+0900) Subject: sd-device: split device_read_db_internal() into two part X-Git-Tag: v242-rc1~244^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b07d0f2a85097e0fd0993abd969ecd967829ca1d;p=thirdparty%2Fsystemd.git sd-device: split device_read_db_internal() into two part The new device_read_db_internal_filename() will be used by a fuzzer. --- diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index 062bfd651c1..49e02db81ed 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -50,6 +50,7 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, int device_tag_index(sd_device *dev, sd_device *dev_old, bool add); int device_update_db(sd_device *device); int device_delete_db(sd_device *device); +int device_read_db_internal_filename(sd_device *device, const char *filename); /* For fuzzer */ int device_read_db_internal(sd_device *device, bool force); static inline int device_read_db(sd_device *device) { return device_read_db_internal(device, false); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 9137a93794b..584e7def8a5 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1273,13 +1273,11 @@ int device_get_id_filename(sd_device *device, const char **ret) { return 0; } -int device_read_db_internal(sd_device *device, bool force) { +int device_read_db_internal_filename(sd_device *device, const char *filename) { _cleanup_free_ char *db = NULL; - char *path; - const char *id, *value; + const char *value; + size_t db_len, i; char key; - size_t db_len; - unsigned i; int r; enum { @@ -1291,22 +1289,14 @@ int device_read_db_internal(sd_device *device, bool force) { } state = PRE_KEY; assert(device); + assert(filename); - if (device->db_loaded || (!force && device->sealed)) - return 0; - - r = device_get_id_filename(device, &id); - if (r < 0) - return r; - - path = strjoina("/run/udev/data/", id); - - r = read_full_file(path, &db, &db_len); + r = read_full_file(filename, &db, &db_len); if (r < 0) { if (r == -ENOENT) return 0; - else - return log_device_debug_errno(device, r, "sd-device: Failed to read db '%s': %m", path); + + return log_device_debug_errno(device, r, "sd-device: Failed to read db '%s': %m", filename); } /* devices with a database entry are initialized */ @@ -1359,13 +1349,31 @@ int device_read_db_internal(sd_device *device, bool force) { break; default: - assert_not_reached("Invalid state when parsing db"); + return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL), "sd-device: invalid db syntax."); } } return 0; } +int device_read_db_internal(sd_device *device, bool force) { + const char *id, *path; + int r; + + assert(device); + + if (device->db_loaded || (!force && device->sealed)) + return 0; + + r = device_get_id_filename(device, &id); + if (r < 0) + return r; + + path = strjoina("/run/udev/data/", id); + + return device_read_db_internal_filename(device, path); +} + _public_ int sd_device_get_is_initialized(sd_device *device) { int r;