summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/libsystemd.sym5
-rw-r--r--src/libsystemd/meson.build3
-rw-r--r--src/libsystemd/sd-bus/bus-message.c30
-rw-r--r--src/libsystemd/sd-hwdb/hwdb-internal.h1
-rw-r--r--src/libsystemd/sd-hwdb/sd-hwdb.c45
5 files changed, 62 insertions, 22 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index ccc321ec33..528e86b663 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -778,3 +778,8 @@ global:
sd_device_open;
sd_device_enumerator_add_nomatch_sysname;
} LIBSYSTEMD_250;
+
+LIBSYSTEMD_252 {
+global:
+ sd_hwdb_new_from_path;
+} LIBSYSTEMD_251;
diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build
index 8a03890d8b..c3eef87b84 100644
--- a/src/libsystemd/meson.build
+++ b/src/libsystemd/meson.build
@@ -222,7 +222,8 @@ tests += [
libglib,
libgobject,
libgio,
- libdbus]],
+ libdbus,
+ libm]],
[files('sd-bus/test-bus-signature.c'),
[],
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index b77372c3a0..026ec101e3 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -428,7 +428,7 @@ int bus_message_from_header(
_cleanup_free_ sd_bus_message *m = NULL;
struct bus_header *h;
- size_t a, label_sz;
+ size_t a, label_sz = 0; /* avoid false maybe-uninitialized warning */
assert(bus);
assert(header || header_accessible <= 0);
@@ -506,7 +506,10 @@ int bus_message_from_header(
m->fields_size = BUS_MESSAGE_BSWAP32(m, h->dbus1.fields_size);
m->body_size = BUS_MESSAGE_BSWAP32(m, h->dbus1.body_size);
- if (sizeof(struct bus_header) + ALIGN8(m->fields_size) + m->body_size != message_size)
+ assert(message_size >= sizeof(struct bus_header));
+ if (m->fields_size > message_size - sizeof(struct bus_header) ||
+ ALIGN8(m->fields_size) > message_size - sizeof(struct bus_header) ||
+ m->body_size != message_size - sizeof(struct bus_header) - ALIGN8(m->fields_size))
return -EBADMSG;
}
@@ -3061,15 +3064,21 @@ void bus_body_part_unmap(struct bus_body_part *part) {
return;
}
-static int buffer_peek(const void *p, uint32_t sz, size_t *rindex, size_t align, size_t nbytes, void **r) {
+static int buffer_peek(const void *p, size_t sz, size_t *rindex, size_t align, size_t nbytes, void **r) {
size_t k, start, end;
assert(rindex);
assert(align > 0);
- start = ALIGN_TO((size_t) *rindex, align);
- end = start + nbytes;
+ start = ALIGN_TO(*rindex, align);
+ if (start > sz)
+ return -EBADMSG;
+
+ /* Avoid overflow below */
+ if (nbytes > SIZE_MAX - start)
+ return -EBADMSG;
+ end = start + nbytes;
if (end > sz)
return -EBADMSG;
@@ -3272,10 +3281,17 @@ static int message_peek_body(
assert(rindex);
assert(align > 0);
- start = ALIGN_TO((size_t) *rindex, align);
+ start = ALIGN_TO(*rindex, align);
+ if (start > m->user_body_size)
+ return -EBADMSG;
+
padding = start - *rindex;
- end = start + nbytes;
+ /* Avoid overflow below */
+ if (nbytes > SIZE_MAX - start)
+ return -EBADMSG;
+
+ end = start + nbytes;
if (end > m->user_body_size)
return -EBADMSG;
diff --git a/src/libsystemd/sd-hwdb/hwdb-internal.h b/src/libsystemd/sd-hwdb/hwdb-internal.h
index 5ddc2211e6..62d27f7b89 100644
--- a/src/libsystemd/sd-hwdb/hwdb-internal.h
+++ b/src/libsystemd/sd-hwdb/hwdb-internal.h
@@ -2,6 +2,7 @@
#pragma once
#include <stdint.h>
+#include <sys/stat.h>
#include "def.h"
#include "hashmap.h"
diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c
index 748cf26934..f73d1fc21e 100644
--- a/src/libsystemd/sd-hwdb/sd-hwdb.c
+++ b/src/libsystemd/sd-hwdb/sd-hwdb.c
@@ -281,9 +281,9 @@ static int trie_search_f(sd_hwdb *hwdb, const char *search) {
return 0;
}
-_public_ int sd_hwdb_new(sd_hwdb **ret) {
+static int hwdb_new(const char *path, sd_hwdb **ret) {
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
- const char *hwdb_bin_path;
+ const char *hwdb_bin_path = NULL;
const char sig[] = HWDB_SIG;
assert_return(ret, -EINVAL);
@@ -294,19 +294,26 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
hwdb->n_ref = 1;
- /* find hwdb.bin in hwdb_bin_paths */
- NULSTR_FOREACH(hwdb_bin_path, hwdb_bin_paths) {
- log_debug("Trying to open \"%s\"...", hwdb_bin_path);
- hwdb->f = fopen(hwdb_bin_path, "re");
- if (hwdb->f)
- break;
- if (errno != ENOENT)
- return log_debug_errno(errno, "Failed to open %s: %m", hwdb_bin_path);
- }
+ /* find hwdb.bin in hwdb_bin_paths, or from an explicit path if provided */
+ if (!isempty(path)) {
+ log_debug("Trying to open \"%s\"...", path);
+ hwdb->f = fopen(path, "re");
+ if (!hwdb->f)
+ return log_debug_errno(errno, "Failed to open %s: %m", path);
+ } else {
+ NULSTR_FOREACH(hwdb_bin_path, hwdb_bin_paths) {
+ log_debug("Trying to open \"%s\"...", hwdb_bin_path);
+ hwdb->f = fopen(hwdb_bin_path, "re");
+ if (hwdb->f)
+ break;
+ if (errno != ENOENT)
+ return log_debug_errno(errno, "Failed to open %s: %m", hwdb_bin_path);
+ }
- if (!hwdb->f)
- return log_debug_errno(SYNTHETIC_ERRNO(ENOENT),
- "hwdb.bin does not exist, please run 'systemd-hwdb update'");
+ if (!hwdb->f)
+ return log_debug_errno(SYNTHETIC_ERRNO(ENOENT),
+ "hwdb.bin does not exist, please run 'systemd-hwdb update'");
+ }
if (fstat(fileno(hwdb->f), &hwdb->st) < 0)
return log_debug_errno(errno, "Failed to stat %s: %m", hwdb_bin_path);
@@ -339,6 +346,16 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
return 0;
}
+_public_ int sd_hwdb_new_from_path(const char *path, sd_hwdb **ret) {
+ assert_return(!isempty(path), -EINVAL);
+
+ return hwdb_new(path, ret);
+}
+
+_public_ int sd_hwdb_new(sd_hwdb **ret) {
+ return hwdb_new(NULL, ret);
+}
+
static sd_hwdb *hwdb_free(sd_hwdb *hwdb) {
assert(hwdb);