]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostname-setup: use strchr() to find wildcard character 36707/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Mar 2025 21:46:36 +0000 (06:46 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Mar 2025 21:48:57 +0000 (06:48 +0900)
Addresses https://github.com/systemd/systemd/pull/36647#discussion_r1990048751.

src/shared/hostname-setup.c

index af89f92bdc43b7c7bb182ffc97056c207db41950..33b6a05ad860aff3ac7847996ec14a0cc2dab15e 100644 (file)
@@ -268,9 +268,10 @@ int hostname_substitute_wildcards(char *name) {
          * Note that this does not directly use the machine ID, because that's not necessarily supposed to be
          * public information to be broadcast on the network, while the hostname certainly is. */
 
-        for (char *n = name; *n; n++) {
-                if (*n != '?')
-                        continue;
+        for (char *n = name; ; n++) {
+                n = strchr(n, '?');
+                if (!n)
+                        return 0;
 
                 if (left_bits <= 0) {
                         if (sd_id128_is_null(mid)) {
@@ -293,8 +294,6 @@ int hostname_substitute_wildcards(char *name) {
                 h >>= 4;
                 left_bits -= 4;
         }
-
-        return 0;
 }
 
 char* get_default_hostname(void) {