From: Lennart Poettering Date: Thu, 14 May 2026 06:45:35 +0000 (+0200) Subject: sd-json: add SD_JSON_PARSE_SEEK0 flag X-Git-Tag: v261-rc1~120^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=584ee9ffe57f0fd1ac34da97c2717f10f978b69f;p=thirdparty%2Fsystemd.git sd-json: add SD_JSON_PARSE_SEEK0 flag --- diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c index a7ff526bc8e..e95ff685228 100644 --- a/src/libsystemd/sd-json/sd-json.c +++ b/src/libsystemd/sd-json/sd-json.c @@ -3502,9 +3502,12 @@ _public_ int sd_json_parse_file_at( _cleanup_free_ char *text = NULL; int r; - if (f) + if (f) { + if (FLAGS_SET(flags, SD_JSON_PARSE_SEEK0) && fseek(f, /* offset= */ 0, SEEK_SET) < 0) + return -errno; + r = read_full_stream(f, &text, NULL); - else + } else r = read_full_file_full(dir_fd, path, UINT64_MAX, SIZE_MAX, 0, NULL, &text, NULL); if (r < 0) return r; diff --git a/src/systemd/sd-json.h b/src/systemd/sd-json.h index 6a197754909..dc71871872e 100644 --- a/src/systemd/sd-json.h +++ b/src/systemd/sd-json.h @@ -184,6 +184,7 @@ __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_json_parse_flags_t) { SD_JSON_PARSE_SENSITIVE = 1 << 0, /* mark variant as "sensitive", i.e. something containing secret key material or such */ SD_JSON_PARSE_MUST_BE_OBJECT = 1 << 1, /* refuse parsing if top-level is not an object */ SD_JSON_PARSE_MUST_BE_ARRAY = 1 << 2, /* refuse parsing if top-level is not an array */ + SD_JSON_PARSE_SEEK0 = 1 << 3, /* seek to offset 0 before reading */ _SD_ENUM_FORCE_S64(JSON_PARSE_FLAGS) } sd_json_parse_flags_t;