mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 14:55:37 +03:00
Merge pull request #20413 from poettering/mempmen
add and use mempmem_safe()
This commit is contained in:
commit
06e8d75a5d
@ -71,6 +71,16 @@ static inline void *memmem_safe(const void *haystack, size_t haystacklen, const
|
||||
return memmem(haystack, haystacklen, needle, needlelen);
|
||||
}
|
||||
|
||||
static inline void *mempmem_safe(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
|
||||
const uint8_t *p;
|
||||
|
||||
p = memmem_safe(haystack, haystacklen, needle, needlelen);
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
return (uint8_t*) p + needlelen;
|
||||
}
|
||||
|
||||
#if HAVE_EXPLICIT_BZERO
|
||||
static inline void* explicit_bzero_safe(void *p, size_t l) {
|
||||
if (l > 0)
|
||||
|
@ -159,12 +159,11 @@ static int get_file_version(int fd, char **v) {
|
||||
if (buf == MAP_FAILED)
|
||||
return log_error_errno(errno, "Failed to memory map EFI binary: %m");
|
||||
|
||||
s = memmem(buf, st.st_size - 8, "#### LoaderInfo: ", 17);
|
||||
s = mempmem_safe(buf, st.st_size - 8, "#### LoaderInfo: ", 17);
|
||||
if (!s)
|
||||
goto finish;
|
||||
s += 17;
|
||||
|
||||
e = memmem(s, st.st_size - (s - buf), " ####", 5);
|
||||
e = memmem_safe(s, st.st_size - (s - buf), " ####", 5);
|
||||
if (!e || e - s < 3) {
|
||||
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Malformed version string.");
|
||||
goto finish;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "io-util.h"
|
||||
#include "memory-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "pull-common.h"
|
||||
@ -342,7 +343,7 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
|
||||
|
||||
line = strjoina(job->checksum, " *", fn, "\n");
|
||||
|
||||
p = memmem(checksum_job->payload,
|
||||
p = memmem_safe(checksum_job->payload,
|
||||
checksum_job->payload_size,
|
||||
line,
|
||||
strlen(line));
|
||||
@ -350,7 +351,7 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
|
||||
if (!p) {
|
||||
line = strjoina(job->checksum, " ", fn, "\n");
|
||||
|
||||
p = memmem(checksum_job->payload,
|
||||
p = memmem_safe(checksum_job->payload,
|
||||
checksum_job->payload_size,
|
||||
line,
|
||||
strlen(line));
|
||||
|
@ -173,12 +173,12 @@ static int bus_socket_auth_verify_client(sd_bus *b) {
|
||||
if (!d)
|
||||
return 0;
|
||||
|
||||
e = memmem(d + 2, b->rbuffer_size - (d - (char*) b->rbuffer) - 2, "\r\n", 2);
|
||||
e = memmem_safe(d + 2, b->rbuffer_size - (d - (char*) b->rbuffer) - 2, "\r\n", 2);
|
||||
if (!e)
|
||||
return 0;
|
||||
|
||||
if (b->accept_fd) {
|
||||
f = memmem(e + 2, b->rbuffer_size - (e - (char*) b->rbuffer) - 2, "\r\n", 2);
|
||||
f = memmem_safe(e + 2, b->rbuffer_size - (e - (char*) b->rbuffer) - 2, "\r\n", 2);
|
||||
if (!f)
|
||||
return 0;
|
||||
|
||||
@ -399,7 +399,7 @@ static int bus_socket_auth_verify_server(sd_bus *b) {
|
||||
for (;;) {
|
||||
/* Check if line is complete */
|
||||
line = (char*) b->rbuffer + b->auth_rbegin;
|
||||
e = memmem(line, b->rbuffer_size - b->auth_rbegin, "\r\n", 2);
|
||||
e = memmem_safe(line, b->rbuffer_size - b->auth_rbegin, "\r\n", 2);
|
||||
if (!e)
|
||||
return processed;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user