summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp-lease.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-01-20 15:36:09 +0100
committerLennart Poettering <lennart@poettering.net>2023-01-21 10:45:25 +0100
commit7153213e406815ae0083789c211d8b77c79588d5 (patch)
treeae980516803b4a2bb512d9ffaa88148e66f1ec62 /src/libsystemd-network/sd-dhcp-lease.c
parent9e2e3342ca5d219085c8f00ef0c2209f0d9b48ec (diff)
downloadsystemd-7153213e406815ae0083789c211d8b77c79588d5.tar.gz
string-util: add common implementation of function that converts sized character buffers to NUL terminated C strings
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-lease.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-lease.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index b14ad57071..02c6a6e0d7 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -376,6 +376,8 @@ static int lease_parse_be32(const uint8_t *option, size_t len, be32_t *ret) {
}
static int lease_parse_string(const uint8_t *option, size_t len, char **ret) {
+ int r;
+
assert(option);
assert(ret);
@@ -388,12 +390,9 @@ static int lease_parse_string(const uint8_t *option, size_t len, char **ret) {
* One trailing NUL byte is OK, we don't mind. See:
* https://github.com/systemd/systemd/issues/1337
*/
- if (memchr(option, 0, len - 1))
- return -EINVAL;
-
- string = memdup_suffix0((const char *) option, len);
- if (!string)
- return -ENOMEM;
+ r = make_cstring((const char*) option, len, MAKE_CSTRING_ALLOW_TRAILING_NUL, &string);
+ if (r < 0)
+ return r;
free_and_replace(*ret, string);
}