mirror of
https://github.com/systemd/systemd.git
synced 2024-12-03 15:23:36 +08:00
pcrextend: fix minor memory leak
Also, simplify the code a bit by using json_dispatch_unbase64_iovec().
This commit is contained in:
parent
2bab4caaf9
commit
c7896cecea
@ -247,35 +247,24 @@ static int extend_now(unsigned pcr, const void *data, size_t size, Tpm2Userspace
|
|||||||
typedef struct MethodExtendParameters {
|
typedef struct MethodExtendParameters {
|
||||||
unsigned pcr;
|
unsigned pcr;
|
||||||
const char *text;
|
const char *text;
|
||||||
void *data;
|
struct iovec data;
|
||||||
size_t data_size;
|
|
||||||
} MethodExtendParameters;
|
} MethodExtendParameters;
|
||||||
|
|
||||||
static int json_dispatch_binary_data(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) {
|
static void method_extend_parameters_done(MethodExtendParameters *p) {
|
||||||
MethodExtendParameters *p = ASSERT_PTR(userdata);
|
assert(p);
|
||||||
_cleanup_free_ void *d = NULL;
|
|
||||||
size_t l;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
r = json_variant_unbase64(variant, &d, &l);
|
iovec_done(&p->data);
|
||||||
if (r < 0)
|
|
||||||
return json_log(variant, flags, r, "JSON variant is not a base64 string.");
|
|
||||||
|
|
||||||
free_and_replace(p->data, d);
|
|
||||||
p->data_size = l;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vl_method_extend(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
static int vl_method_extend(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||||
|
|
||||||
static const JsonDispatch dispatch_table[] = {
|
static const JsonDispatch dispatch_table[] = {
|
||||||
{ "pcr", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint, offsetof(MethodExtendParameters, pcr), JSON_MANDATORY },
|
{ "pcr", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint, offsetof(MethodExtendParameters, pcr), JSON_MANDATORY },
|
||||||
{ "text", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(MethodExtendParameters, text), 0 },
|
{ "text", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(MethodExtendParameters, text), 0 },
|
||||||
{ "data", JSON_VARIANT_STRING, json_dispatch_binary_data, 0, 0 },
|
{ "data", JSON_VARIANT_STRING, json_dispatch_unbase64_iovec, offsetof(MethodExtendParameters, data), 0 },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
MethodExtendParameters p = {
|
_cleanup_(method_extend_parameters_done) MethodExtendParameters p = {
|
||||||
.pcr = UINT_MAX,
|
.pcr = UINT_MAX,
|
||||||
};
|
};
|
||||||
int r;
|
int r;
|
||||||
@ -291,12 +280,12 @@ static int vl_method_extend(Varlink *link, JsonVariant *parameters, VarlinkMetho
|
|||||||
|
|
||||||
if (p.text) {
|
if (p.text) {
|
||||||
/* Specifying both the text string and the binary data is not allowed */
|
/* Specifying both the text string and the binary data is not allowed */
|
||||||
if (p.data)
|
if (p.data.iov_base)
|
||||||
return varlink_errorb(link, VARLINK_ERROR_INVALID_PARAMETER, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("parameter", "data")));
|
return varlink_errorb(link, VARLINK_ERROR_INVALID_PARAMETER, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("parameter", "data")));
|
||||||
|
|
||||||
r = extend_now(p.pcr, p.text, strlen(p.text), _TPM2_USERSPACE_EVENT_TYPE_INVALID);
|
r = extend_now(p.pcr, p.text, strlen(p.text), _TPM2_USERSPACE_EVENT_TYPE_INVALID);
|
||||||
} else if (p.data)
|
} else if (p.data.iov_base)
|
||||||
r = extend_now(p.pcr, p.data, p.data_size, _TPM2_USERSPACE_EVENT_TYPE_INVALID);
|
r = extend_now(p.pcr, p.data.iov_base, p.data.iov_len, _TPM2_USERSPACE_EVENT_TYPE_INVALID);
|
||||||
else
|
else
|
||||||
return varlink_errorb(link, VARLINK_ERROR_INVALID_PARAMETER, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("parameter", "text")));
|
return varlink_errorb(link, VARLINK_ERROR_INVALID_PARAMETER, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("parameter", "text")));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user