[LTP] [PATCH v3 29/36] keyctl33: Negative tests for KEYCTL_PKEY_*

Cyril Hrubis chrubis@suse.cz
Fri Sep 18 17:31:34 CEST 2026


Hi!
> +static void run(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +
> +	if (tc->op == KEYCTL_PKEY_QUERY) {
> +		TST_EXP_FAIL(keyctl(KEYCTL_PKEY_QUERY, (unsigned long)*tc->key,
> +				    tc->arg3, (unsigned long)tc->info,
> +				    (unsigned long)query_buf),
> +			     tc->exp_errno,
> +			     "%s", tc->desc);
> +		return;
> +	}
> +
> +	memset(params, 0, sizeof(*params));
> +	params->key_id = *tc->key;
> +	params->in_len = tc->in_len;
> +	params->out_len = tc->out_in2_len;
> +
> +	if (tc->op == KEYCTL_PKEY_VERIFY) {
> +		TST_EXP_FAIL(keyctl(tc->op, (unsigned long)params,
> +				    (unsigned long)tc->info,
> +				    (unsigned long)in_buf,
> +				    (unsigned long)out_buf),
> +			     tc->exp_errno,
> +			     "%s", tc->desc);
> +	} else {
> +		TST_EXP_FAIL2(keyctl(tc->op, (unsigned long)params,
> +				     (unsigned long)tc->info,
> +				     (unsigned long)in_buf,
> +				     (unsigned long)out_buf),
> +			      tc->exp_errno,
> +			      "%s", tc->desc);
> +	}

Well I would have coded this part a bit more tidily:

	switch (tc->op) {
	case KEYCTL_PKEY_QUERY:
		verify_pkey_query(tc);
	break;
	case KEYCTL_PKEY_VERIFY:
		verify_pkey_verify(tc);
	break;
	default:
		verify_pkey(tc);
	break;
	}

And moved the code into separate functions, no functional changes, just
a bit nicer flow.


Otherwise:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>


-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list