]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk,partx: avoid strcasecmp() for ASCII-only strings
authorKarel Zak <kzak@redhat.com>
Tue, 1 Apr 2025 15:45:01 +0000 (17:45 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 2 Apr 2025 09:06:41 +0000 (11:06 +0200)
Use cctype.h for locale-independent string comparison and to avoid
tricky string conversions like in tr_TR locales.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
disk-utils/fdisk-list.h
disk-utils/partx.c

index d4057eedbf11dac52ea125124984aba993a895f6..d0bb57aaf15b1a3d2d02d3596c6633799c2a246d 100644 (file)
@@ -53,6 +53,7 @@
 #endif
 
 #include "c.h"
+#include "cctype.h"
 #include "closestream.h"
 #include "nls.h"
 #include "widechar.h"
@@ -2507,7 +2508,7 @@ static int main_menu_action(struct cfdisk *cf, int key)
                          buf, sizeof(buf));
 
                ref = 1;
-               if (rc <= 0 || (strcasecmp(buf, "yes") != 0 &&
+               if (rc <= 0 || (c_strcasecmp(buf, "yes") != 0 &&
                                strcasecmp(buf, _("yes")) != 0)) {
                        info = _("Did not write partition table to disk.");
                        break;
index 1839301dd9f8f55f3b73ddbb0cfa801c7aa519f0..8e5ea58bb664472285ab927095d128b7737369f0 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef UTIL_LINUX_FDISK_LIST_H
 #define UTIL_LINUX_FDISK_LIST_H
 
+#include "cctype.h"
+
 extern void list_disklabel(struct fdisk_context *cxt);
 extern void list_disk_identifier(struct fdisk_context *cxt);
 extern void list_disk_geometry(struct fdisk_context *cxt);
@@ -51,7 +53,7 @@ static inline int wipemode_from_string(const char *str)
                return -EINVAL;
 
        for (i = 0; i < ARRAY_SIZE(modes); i++) {
-               if (strcasecmp(str, modes[i]) == 0)
+               if (c_strcasecmp(str, modes[i]) == 0)
                        return i;
        }
 
index b0d552c3cf4d267ebaa29097b382fa4e8177e7c1..49d506158076a25f9d4bcb559734d635be22792b 100644 (file)
@@ -162,7 +162,7 @@ static int column_name_to_id(const char *name, size_t namesz)
        for (i = 0; i < NCOLS; i++) {
                const char *cn = infos[i].name;
 
-               if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
+               if (!c_strncasecmp(name, cn, namesz) && !*(cn + namesz))
                        return i;
        }
        warnx(_("unknown column: %s"), name);