[LTP] [PATCH v8 2/2] coredump02: Verify ELF structure and notes

Cyril Hrubis chrubis@suse.cz
Tue Sep 8 17:59:07 CEST 2026


Hi!
> +static const void *core_at(size_t off, size_t need)
> +{
> +	if (off > core_len || need > core_len - off)
> +		tst_brk(TFAIL, "core file truncated at %zu (need %zu, have %zu)",
> +			off, need, core_len);
> +
> +	return core_buf + off;
> +}
> +
> +static void handle_note(uint32_t type, const void *desc, size_t descsz, pid_t pid)
> +{
> +	if (type == NT_PRPSINFO && descsz >= sizeof(struct elf_prpsinfo)) {
> +		struct elf_prpsinfo info;
> +		char name[sizeof(info.pr_fname) + 1] = {0};
> +
> +		memcpy(&info, desc, sizeof(info));
> +		memcpy(name, info.pr_fname, sizeof(info.pr_fname));
> +
> +		TST_EXP_EQ_STR(name, "coredump02");

We do have TST_EXP_EQ_STRN() there is no need for the memcpy.

Also as long as the alignment is proper there is no need for the first
memcpy() either.

I would have expected that the elf headers are aligned properly and
since we loaded the whole file into aligned buffer (malloc() aligns
properly), it should be safe to just cast the desc pointer into the
strcut elf_prpsinfo *info = desc;  and acces info.pr_name directly from
the buffer.

> +		prpsinfo_seen = 1;
> +	} else if (type == NT_PRSTATUS && descsz >= sizeof(struct elf_prstatus)) {
> +		struct elf_prstatus st;
> +
> +		memcpy(&st, desc, sizeof(st));

Here as well.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list