mirror of
https://github.com/systemd/systemd
synced 2026-03-25 08:14:54 +01:00
Compare commits
9 Commits
836fb00f21
...
5afcf89ca2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5afcf89ca2 | ||
|
|
76f226d71b | ||
|
|
06e8d75a5d | ||
|
|
9cbf128202 | ||
|
|
0eec7f5ffa | ||
|
|
e8b08edcdf | ||
|
|
d8782cc5c2 | ||
|
|
de949e911e | ||
|
|
0c42b61348 |
@ -44,10 +44,11 @@ typedef void (*free_func_t)(void *p);
|
|||||||
|
|
||||||
#define malloc0(n) (calloc(1, (n) ?: 1))
|
#define malloc0(n) (calloc(1, (n) ?: 1))
|
||||||
|
|
||||||
static inline void *mfree(void *memory) {
|
#define mfree(memory) \
|
||||||
free(memory);
|
({ \
|
||||||
return NULL;
|
free(memory); \
|
||||||
}
|
(typeof(memory)) NULL; \
|
||||||
|
})
|
||||||
|
|
||||||
#define free_and_replace(a, b) \
|
#define free_and_replace(a, b) \
|
||||||
({ \
|
({ \
|
||||||
|
|||||||
@ -71,6 +71,16 @@ static inline void *memmem_safe(const void *haystack, size_t haystacklen, const
|
|||||||
return memmem(haystack, haystacklen, needle, needlelen);
|
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
|
#if HAVE_EXPLICIT_BZERO
|
||||||
static inline void* explicit_bzero_safe(void *p, size_t l) {
|
static inline void* explicit_bzero_safe(void *p, size_t l) {
|
||||||
if (l > 0)
|
if (l > 0)
|
||||||
|
|||||||
@ -159,12 +159,11 @@ static int get_file_version(int fd, char **v) {
|
|||||||
if (buf == MAP_FAILED)
|
if (buf == MAP_FAILED)
|
||||||
return log_error_errno(errno, "Failed to memory map EFI binary: %m");
|
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)
|
if (!s)
|
||||||
goto finish;
|
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) {
|
if (!e || e - s < 3) {
|
||||||
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Malformed version string.");
|
r = log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Malformed version string.");
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|||||||
@ -5497,10 +5497,19 @@ const char *unit_label_path(const Unit *u) {
|
|||||||
/* Returns the file system path to use for MAC access decisions, i.e. the file to read the SELinux label off
|
/* Returns the file system path to use for MAC access decisions, i.e. the file to read the SELinux label off
|
||||||
* when validating access checks. */
|
* when validating access checks. */
|
||||||
|
|
||||||
|
if (IN_SET(u->load_state, UNIT_MASKED, UNIT_NOT_FOUND, UNIT_MERGED))
|
||||||
|
return NULL; /* Shortcut things if we know there is no real, relevant unit file around */
|
||||||
|
|
||||||
p = u->source_path ?: u->fragment_path;
|
p = u->source_path ?: u->fragment_path;
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (IN_SET(u->load_state, UNIT_LOADED, UNIT_BAD_SETTING, UNIT_ERROR))
|
||||||
|
return p; /* Shortcut things, if we successfully loaded at least some stuff from the unit file */
|
||||||
|
|
||||||
|
/* Not loaded yet, we need to go to disk */
|
||||||
|
assert(u->load_state == UNIT_STUB);
|
||||||
|
|
||||||
/* If a unit is masked, then don't read the SELinux label of /dev/null, as that really makes no sense */
|
/* If a unit is masked, then don't read the SELinux label of /dev/null, as that really makes no sense */
|
||||||
if (null_or_empty_path(p) > 0)
|
if (null_or_empty_path(p) > 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include "escape.h"
|
#include "escape.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
#include "io-util.h"
|
#include "io-util.h"
|
||||||
|
#include "memory-util.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "process-util.h"
|
#include "process-util.h"
|
||||||
#include "pull-common.h"
|
#include "pull-common.h"
|
||||||
@ -342,7 +343,7 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
|
|||||||
|
|
||||||
line = strjoina(job->checksum, " *", fn, "\n");
|
line = strjoina(job->checksum, " *", fn, "\n");
|
||||||
|
|
||||||
p = memmem(checksum_job->payload,
|
p = memmem_safe(checksum_job->payload,
|
||||||
checksum_job->payload_size,
|
checksum_job->payload_size,
|
||||||
line,
|
line,
|
||||||
strlen(line));
|
strlen(line));
|
||||||
@ -350,7 +351,7 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
|
|||||||
if (!p) {
|
if (!p) {
|
||||||
line = strjoina(job->checksum, " ", fn, "\n");
|
line = strjoina(job->checksum, " ", fn, "\n");
|
||||||
|
|
||||||
p = memmem(checksum_job->payload,
|
p = memmem_safe(checksum_job->payload,
|
||||||
checksum_job->payload_size,
|
checksum_job->payload_size,
|
||||||
line,
|
line,
|
||||||
strlen(line));
|
strlen(line));
|
||||||
|
|||||||
@ -1134,30 +1134,24 @@ static int client_parse_message(
|
|||||||
|
|
||||||
switch (optcode) {
|
switch (optcode) {
|
||||||
case SD_DHCP6_OPTION_CLIENTID:
|
case SD_DHCP6_OPTION_CLIENTID:
|
||||||
if (clientid) {
|
if (clientid)
|
||||||
log_dhcp6_client(client, "%s contains multiple clientids",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple clientids",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (optlen != client->duid_len ||
|
if (optlen != client->duid_len ||
|
||||||
memcmp(&client->duid, optval, optlen) != 0) {
|
memcmp(&client->duid, optval, optlen) != 0)
|
||||||
log_dhcp6_client(client, "%s DUID does not match",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s DUID does not match",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
clientid = true;
|
clientid = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SD_DHCP6_OPTION_SERVERID:
|
case SD_DHCP6_OPTION_SERVERID:
|
||||||
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
|
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
|
||||||
if (r >= 0) {
|
if (r >= 0)
|
||||||
log_dhcp6_client(client, "%s contains multiple serverids",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple serverids",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = dhcp6_lease_set_serverid(lease, optval, optlen);
|
r = dhcp6_lease_set_serverid(lease, optval, optlen);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -1180,20 +1174,16 @@ static int client_parse_message(
|
|||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (status > 0) {
|
if (status > 0)
|
||||||
log_dhcp6_client(client, "%s Status %s",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s Status %s",
|
||||||
dhcp6_message_type_to_string(message->type),
|
dhcp6_message_type_to_string(message->type),
|
||||||
dhcp6_message_status_to_string(status));
|
dhcp6_message_status_to_string(status));
|
||||||
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SD_DHCP6_OPTION_IA_NA:
|
case SD_DHCP6_OPTION_IA_NA:
|
||||||
if (client->state == DHCP6_STATE_INFORMATION_REQUEST) {
|
if (client->state == DHCP6_STATE_INFORMATION_REQUEST) {
|
||||||
log_dhcp6_client(client, "Information request ignoring IA NA option");
|
log_dhcp6_client(client, "Ignoring IA NA option in information requesting mode.");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1210,23 +1200,20 @@ static int client_parse_message(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (client->ia_na.ia_na.id != iaid_lease) {
|
if (client->ia_na.ia_na.id != iaid_lease)
|
||||||
log_dhcp6_client(client, "%s has wrong IAID for IA NA",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has wrong IAID for IA NA",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lease->ia.addresses) {
|
if (lease->ia.addresses) {
|
||||||
lt_t1 = MIN(lt_t1, be32toh(lease->ia.ia_na.lifetime_t1));
|
lt_t1 = MIN(lt_t1, be32toh(lease->ia.ia_na.lifetime_t1));
|
||||||
lt_t2 = MIN(lt_t2, be32toh(lease->ia.ia_na.lifetime_t1));
|
lt_t2 = MIN(lt_t2, be32toh(lease->ia.ia_na.lifetime_t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SD_DHCP6_OPTION_IA_PD:
|
case SD_DHCP6_OPTION_IA_PD:
|
||||||
if (client->state == DHCP6_STATE_INFORMATION_REQUEST) {
|
if (client->state == DHCP6_STATE_INFORMATION_REQUEST) {
|
||||||
log_dhcp6_client(client, "Information request ignoring IA PD option");
|
log_dhcp6_client(client, "Ignoring IA PD option in information requesting mode.");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1243,11 +1230,9 @@ static int client_parse_message(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (client->ia_pd.ia_pd.id != iaid_lease) {
|
if (client->ia_pd.ia_pd.id != iaid_lease)
|
||||||
log_dhcp6_client(client, "%s has wrong IAID for IA PD",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has wrong IAID for IA PD",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lease->pd.addresses) {
|
if (lease->pd.addresses) {
|
||||||
lt_t1 = MIN(lt_t1, be32toh(lease->pd.ia_pd.lifetime_t1));
|
lt_t1 = MIN(lt_t1, be32toh(lease->pd.ia_pd.lifetime_t1));
|
||||||
@ -1309,26 +1294,20 @@ static int client_parse_message(
|
|||||||
pos += offsetof(DHCP6Option, data) + optlen;
|
pos += offsetof(DHCP6Option, data) + optlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ia_na_status > 0 && ia_pd_status > 0) {
|
if (ia_na_status > 0 && ia_pd_status > 0)
|
||||||
log_dhcp6_client(client, "No IA_PD prefix or IA_NA address received. Ignoring.");
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "No IA_PD prefix or IA_NA address received. Ignoring.");
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientid) {
|
if (!clientid)
|
||||||
log_dhcp6_client(client, "%s has incomplete options",
|
return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has incomplete options",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client->state != DHCP6_STATE_INFORMATION_REQUEST) {
|
if (client->state != DHCP6_STATE_INFORMATION_REQUEST) {
|
||||||
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
|
r = dhcp6_lease_get_serverid(lease, NULL, NULL);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_dhcp6_client(client, "%s has no server id",
|
return log_dhcp6_client_errno(client, r, "%s has no server id",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
if (lease->ia.addresses) {
|
if (lease->ia.addresses) {
|
||||||
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
|
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
|
||||||
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
|
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
|
||||||
@ -1338,7 +1317,6 @@ static int client_parse_message(
|
|||||||
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
|
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
|
||||||
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
|
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
client->information_refresh_time_usec = MAX(irt, IRT_MINIMUM);
|
client->information_refresh_time_usec = MAX(irt, IRT_MINIMUM);
|
||||||
|
|
||||||
|
|||||||
@ -173,12 +173,12 @@ static int bus_socket_auth_verify_client(sd_bus *b) {
|
|||||||
if (!d)
|
if (!d)
|
||||||
return 0;
|
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)
|
if (!e)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (b->accept_fd) {
|
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)
|
if (!f)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -399,7 +399,7 @@ static int bus_socket_auth_verify_server(sd_bus *b) {
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
/* Check if line is complete */
|
/* Check if line is complete */
|
||||||
line = (char*) b->rbuffer + b->auth_rbegin;
|
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)
|
if (!e)
|
||||||
return processed;
|
return processed;
|
||||||
|
|
||||||
|
|||||||
@ -47,8 +47,8 @@ DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const D
|
|||||||
if (cname->key->type == DNS_TYPE_CNAME)
|
if (cname->key->type == DNS_TYPE_CNAME)
|
||||||
return dns_resource_key_new(key->class, key->type, cname->cname.name);
|
return dns_resource_key_new(key->class, key->type, cname->cname.name);
|
||||||
else {
|
else {
|
||||||
|
_cleanup_free_ char *destination = NULL;
|
||||||
DnsResourceKey *k;
|
DnsResourceKey *k;
|
||||||
char *destination = NULL;
|
|
||||||
|
|
||||||
r = dns_name_change_suffix(dns_resource_key_name(key), dns_resource_key_name(cname->key), cname->dname.name, &destination);
|
r = dns_name_change_suffix(dns_resource_key_name(key), dns_resource_key_name(cname->key), cname->dname.name, &destination);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -58,8 +58,9 @@ DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const D
|
|||||||
|
|
||||||
k = dns_resource_key_new_consume(key->class, key->type, destination);
|
k = dns_resource_key_new_consume(key->class, key->type, destination);
|
||||||
if (!k)
|
if (!k)
|
||||||
return mfree(destination);
|
return NULL;
|
||||||
|
|
||||||
|
TAKE_PTR(destination);
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user