summaryrefslogtreecommitdiffstats
path: root/src/libsystemd-network/dhcp-option.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/dhcp-option.c
parenthwdb: Add touchpad toggle mapping for System76 Pangolin 12 (diff)
downloadsystemd-7153213e406815ae0083789c211d8b77c79588d5.tar.xz
systemd-7153213e406815ae0083789c211d8b77c79588d5.zip
string-util: add common implementation of function that converts sized character buffers to NUL terminated C strings
Diffstat (limited to 'src/libsystemd-network/dhcp-option.c')
-rw-r--r--src/libsystemd-network/dhcp-option.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/libsystemd-network/dhcp-option.c b/src/libsystemd-network/dhcp-option.c
index 7f49da7c2d..a52259c238 100644
--- a/src/libsystemd-network/dhcp-option.c
+++ b/src/libsystemd-network/dhcp-option.c
@@ -279,6 +279,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
uint8_t code, len;
const uint8_t *option;
size_t offset = 0;
+ int r;
while (offset < buflen) {
code = options[offset ++];
@@ -318,13 +319,9 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
if (error_message) {
_cleanup_free_ char *string = NULL;
- /* Accept a trailing NUL byte */
- 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;
if (!ascii_is_valid(string))
return -EINVAL;