[LTP] [PATCH v2 04/33] keyctl12: Test KEYCTL_DESCRIBE with too small buffer

Petr Vorel pvorel@suse.cz
Tue Sep 15 16:40:14 CEST 2026


> Hi!
> > +static void run(void)
> > +{
> > +	size_t i;
> > +
> > +	memset(buf, 0xAA, sizeof(buf));
> > +	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)buf,
> > +				    desc_len - 1, 0), desc_len);
> > +	if (!TST_PASS)
> > +		return;
> > +
> > +	for (i = 0; i < sizeof(buf); i++) {
> > +		if (buf[i] != (char)0xAA) {
> > +			tst_res(TFAIL,
> > +				"too small buffer was written to at offset %zu",
> > +				i);
> > +			return;
> > +		}
> > +	}

> It may make sense to loop this with:

> 	for (buf_len = 0; buf_len < desc_len; buf_len++) {
> 		...
> 	}

> It should be fast and would increase the coverage..

I suppose you want to check the actual key description in case it's longer than
buffer size.

desc_len is 12, sizeof(buf) is 64 therefore it's safe but I'll change it in v3
so that it works in case of a longer key in the future.

Kind regards,
Petr


More information about the ltp mailing list