bool
decode_nla_xval(struct tcb *const tcp,
const kernel_ulong_t addr,
- const unsigned int len,
+ unsigned int len,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts * const opts = opaque_data;
union {
uint64_t val;
uint8_t bytes[sizeof(uint64_t)];
- } data;
- const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
-
- data.val = 0;
+ } data = { .val = 0 };
- if (len > sizeof(data))
+ if (len > sizeof(data) || len < opts->size)
return false;
- else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
- {
+
+ if (opts->size)
+ len = MIN(len, opts->size);
+
+ const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
+
+ if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs)) {
if (opts->process_fn)
data.val = opts->process_fn(data.val);
if (opts->prefix)
.xlat_size = inet_protocols_size,
.xt = XT_SORTED,
.dflt = "IPPROTO_???",
+ .size = 1,
};
return decode_nla_xval(tcp, addr, len, &opts);
bool
decode_nla_flags(struct tcb *const tcp,
const kernel_ulong_t addr,
- const unsigned int len,
+ unsigned int len,
const void *const opaque_data)
{
const struct decode_nla_xlat_opts * const opts = opaque_data;
uint64_t flags;
uint8_t bytes[sizeof(uint64_t)];
} data = { .flags = 0 };
+
+ if (len > sizeof(data) || len < opts->size)
+ return false;
+
+ if (opts->size)
+ len = MIN(len, opts->size);
+
const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
if (opts->xt == XT_INDEXED)
error_func_msg("indexed xlats are currently incompatible with "
"printflags");
- if (len > sizeof(data))
- return false;
- else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
- {
+ if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs)) {
if (opts->process_fn)
data.flags = opts->process_fn(data.flags);
if (opts->prefix)