]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make use of memory_startswith() at various places 9131/head
authorLennart Poettering <lennart@poettering.net>
Wed, 30 May 2018 11:09:03 +0000 (13:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 May 2018 11:11:51 +0000 (13:11 +0200)
src/basic/log.c
src/coredump/coredump.c
src/import/curl-util.c
src/libsystemd/sd-bus/bus-socket.c
src/shared/dns-domain.c
src/shared/logs-show.c

index 5db65f276f75c3f28ce0224087a60029e9f81a0b..167f0f5533475fd71edc00dfaee5c3edddae2398 100644 (file)
@@ -1037,13 +1037,9 @@ int log_struct_iovec_internal(
                         return -error;
         }
 
-        for (i = 0; i < n_input_iovec; i++) {
-                if (input_iovec[i].iov_len < STRLEN("MESSAGE="))
-                        continue;
-
-                if (memcmp(input_iovec[i].iov_base, "MESSAGE=", STRLEN("MESSAGE=")) == 0)
+        for (i = 0; i < n_input_iovec; i++)
+                if (memory_startswith(input_iovec[i].iov_base, input_iovec[i].iov_len, "MESSAGE="))
                         break;
-        }
 
         if (_unlikely_(i >= n_input_iovec)) /* Couldn't find MESSAGE=? */
                 return -error;
index c1f396b1ac762ee64c61f8498b71292ced8dfc44..1c470e60da86ed87e90f05b641629801700bab66 100644 (file)
@@ -852,21 +852,18 @@ static void map_context_fields(const struct iovec *iovec, const char* context[])
         assert(context);
 
         for (i = 0; i < ELEMENTSOF(context_field_names); i++) {
-                size_t l;
+                char *p;
 
                 if (!context_field_names[i])
                         continue;
 
-                l = strlen(context_field_names[i]);
-                if (iovec->iov_len < l)
-                        continue;
-
-                if (memcmp(iovec->iov_base, context_field_names[i], l) != 0)
+                p = memory_startswith(iovec->iov_base, iovec->iov_len, context_field_names[i]);
+                if (!p)
                         continue;
 
                 /* Note that these strings are NUL terminated, because we made sure that a trailing NUL byte is in the
                  * buffer, though not included in the iov_len count. (see below) */
-                context[i] = (char*) iovec->iov_base + l;
+                context[i] = p;
                 break;
         }
 }
index 0f81866d333b45f86d085a18f9271fb5aac1f979..2fba6e29dd663b064f169ef10d813a0ca3dedaa8 100644 (file)
@@ -365,19 +365,14 @@ struct curl_slist *curl_slist_new(const char *first, ...) {
 }
 
 int curl_header_strdup(const void *contents, size_t sz, const char *field, char **value) {
-        const char *p = contents;
-        size_t l;
+        const char *p;
         char *s;
 
-        l = strlen(field);
-        if (sz < l)
+        p = memory_startswith(contents, sz, field);
+        if (!p)
                 return 0;
 
-        if (memcmp(p, field, l) != 0)
-                return 0;
-
-        p += l;
-        sz -= l;
+        sz -= p - (const char*) contents;
 
         if (memchr(p, 0, sz))
                 return 0;
index 04839bada415d544db18f6b290dc8453f0424007..57c5391423edaded64e704672b8a859806e7693f 100644 (file)
@@ -248,16 +248,13 @@ static bool line_equals(const char *s, size_t m, const char *line) {
 }
 
 static bool line_begins(const char *s, size_t m, const char *word) {
-        size_t l;
-
-        l = strlen(word);
-        if (m < l)
-                return false;
+        const char *p;
 
-        if (memcmp(s, word, l) != 0)
+        p = memory_startswith(s, m, word);
+        if (!p)
                 return false;
 
-        return m == l || (m > l && s[l] == ' ');
+        return IN_SET(*p, 0, ' ');
 }
 
 static int verify_anonymous_token(sd_bus *b, const char *p, size_t l) {
index 5ec9eed8ea7845ea3d00cbb0eaeac62ef9def3a6..f7f544c96c7e5ff5ca81655063e6a7771875455d 100644 (file)
@@ -353,10 +353,7 @@ int dns_label_undo_idna(const char *encoded, size_t encoded_size, char *decoded,
         if (encoded_size <= 0 || encoded_size > DNS_LABEL_MAX)
                 return -EINVAL;
 
-        if (encoded_size < sizeof(IDNA_ACE_PREFIX)-1)
-                return 0;
-
-        if (memcmp(encoded, IDNA_ACE_PREFIX, sizeof(IDNA_ACE_PREFIX) -1) != 0)
+        if (!memory_startswith(encoded, encoded_size, IDNA_ACE_PREFIX))
                 return 0;
 
         input = stringprep_utf8_to_ucs4(encoded, encoded_size, &input_size);
index 47becbf37c31713582f9640d4605324acc64bbec..af788391ad5b5c4a1b359c284a206885f3ed2986 100644 (file)
@@ -832,8 +832,7 @@ static int output_json(
                 char *n;
                 unsigned u;
 
-                if (length >= 9 &&
-                    memcmp(data, "_BOOT_ID=", 9) == 0)
+                if (memory_startswith(data, length, "_BOOT_ID="))
                         continue;
 
                 eq = memchr(data, '=', length);
@@ -882,10 +881,8 @@ static int output_json(
                         size_t m;
                         unsigned u;
 
-                        /* We already printed the boot id, from the data in
-                         * the header, hence let's suppress it here */
-                        if (length >= 9 &&
-                            memcmp(data, "_BOOT_ID=", 9) == 0)
+                        /* We already printed the boot id, from the data in the header, hence let's suppress it here */
+                        if (memory_startswith(data, length, "_BOOT_ID="))
                                 continue;
 
                         eq = memchr(data, '=', length);