systemd/backport-sd-device-minor-optimization-for-sd_device_new_from_.patch
2023-12-18 15:30:01 +08:00

42 lines
1.7 KiB
Diff

From d7ea7c486a0101dae06a9aca290bfafa46bc1fe2 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Sun, 7 Mar 2021 15:24:15 +0900
Subject: [PATCH] sd-device: minor optimization for
sd_device_new_from_device_id()
(cherry picked from commit ff7a8d2938b24cb7ca7b69900395ecf837a43a23)
Conflict:input parameters of parse_ifindex() is different, and it does not affect the function of this patch, so ignore parse_ifindex() modifications
Reference:https://github.com/systemd/systemd-stable/commit/d7ea7c486a0101dae06a9aca290bfafa46bc1fe2
---
src/libsystemd/sd-device/sd-device.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c
index bb4d453cee..da5fd2b734 100644
--- a/src/libsystemd/sd-device/sd-device.c
+++ b/src/libsystemd/sd-device/sd-device.c
@@ -653,15 +653,14 @@ _public_ int sd_device_new_from_device_id(sd_device **ret, const char *id) {
}
case '+': {
- char subsys[PATH_MAX];
- char *sysname;
+ char subsys[NAME_MAX+1]; /* NAME_MAX does not include the trailing NUL. */
+ const char *sysname;
- (void) strscpy(subsys, sizeof(subsys), id + 1);
- sysname = strchr(subsys, ':');
+ sysname = strchr(id + 1, ':');
if (!sysname)
return -EINVAL;
- sysname[0] = '\0';
+ (void) strnscpy(subsys, sizeof(subsys), id + 1, sysname - id - 1);
sysname++;
return sd_device_new_from_subsystem_sysname(ret, subsys, sysname);
--
2.27.0