From: Lennart Poettering Date: Tue, 22 Mar 2022 11:58:55 +0000 (+0100) Subject: sd-device: use path_compare() rather than strcmp() for sorting paths X-Git-Tag: v251-rc1~75^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F22821%2Fhead;p=thirdparty%2Fsystemd.git sd-device: use path_compare() rather than strcmp() for sorting paths When sorting paths it actually matters to use the right comparison function. Example: ``` a/x a-b/y a_/z ``` I think people would probably expect this: ``` a/x a-b/y a_a/z ``` but if you use strcmp() instead of path_compare() you'd instead get: ``` a-b/y a/x a_a/z ``` That's because `/` is between `-` and `a` in the ascii table. I think that's quite confusing, and we shouldn#t order that way hence. As discussed: https://github.com/systemd/systemd/pull/22662#discussion_r831174776 --- diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 1379764156e..14794fb3af5 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -323,7 +323,7 @@ static int device_compare(sd_device * const *a, sd_device * const *b) { if (r != 0) return r; - return strcmp(devpath_a, devpath_b); + return path_compare(devpath_a, devpath_b); } static int enumerator_sort_devices(sd_device_enumerator *enumerator) {