diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-20 15:36:09 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-21 10:45:25 +0100 |
commit | 7153213e406815ae0083789c211d8b77c79588d5 (patch) | |
tree | ae980516803b4a2bb512d9ffaa88148e66f1ec62 /src/creds/creds.c | |
parent | hwdb: Add touchpad toggle mapping for System76 Pangolin 12 (diff) | |
download | systemd-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/creds/creds.c')
-rw-r--r-- | src/creds/creds.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/creds/creds.c b/src/creds/creds.c index 71bf355b38..3eb94cd36a 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -326,16 +326,12 @@ static int write_blob(FILE *f, const void *data, size_t size) { if (arg_transcode == TRANSCODE_OFF && arg_json_format_flags != JSON_FORMAT_OFF) { - _cleanup_(erase_and_freep) char *suffixed = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; - if (memchr(data, 0, size)) - return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Credential data contains embedded NUL, can't parse as JSON."); - - suffixed = memdup_suffix0(data, size); - if (!suffixed) - return log_oom(); + r = make_cstring(data, size, MAKE_CSTRING_REFUSE_TRAILING_NUL, &suffixed); + if (r < 0) + return log_error_errno(r, "Unable to convert binary string to C string: %m"); r = json_parse(suffixed, JSON_PARSE_SENSITIVE, &v, NULL, NULL); if (r < 0) |