Merge pull request #9131 from poettering/memory-startswith
add new memory_startswith() helper and make use of it everywhere
This commit is contained in:
+2
-6
@@ -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;
|
||||
|
||||
@@ -209,3 +209,21 @@ static inline size_t strlen_ptr(const char *s) {
|
||||
|
||||
return strlen(s);
|
||||
}
|
||||
|
||||
/* Like startswith(), but operates on arbitrary memory blocks */
|
||||
static inline void *memory_startswith(const void *p, size_t sz, const char *token) {
|
||||
size_t n;
|
||||
|
||||
assert(token);
|
||||
|
||||
n = strlen(token);
|
||||
if (sz < n)
|
||||
return NULL;
|
||||
|
||||
assert(p);
|
||||
|
||||
if (memcmp(p, token, n) != 0)
|
||||
return NULL;
|
||||
|
||||
return (uint8_t*) p + n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user