summaryrefslogtreecommitdiff
path: root/src/creds
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/creds
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/creds')
-rw-r--r--src/creds/creds.c10
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)