1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Support different types in the parameter store

The test framework stores size_t and int32_t values in the parameter store
by converting them all to int. This is ok in practice, since we assume int
covers int32_t and we don't have test data larger than 2GB. But it's
confusing and error-prone. So make the parameter store a union, which allows
size_t values not to be potentially truncated and makes the code a little
clearer.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2022-12-04 13:10:55 +01:00
parent a299043d58
commit 9ad7bd3060
6 changed files with 61 additions and 14 deletions

View File

@ -28,7 +28,7 @@ int verify_string(char **str)
* integer value.
*
* \param str Input string.
* \param value Pointer to int for output value.
* \param p_value Pointer to output value.
*
* \return 0 if success else 1
*/
@ -203,7 +203,8 @@ static int parse_arguments(char *buf, size_t len, char **params,
*
* \return 0 for success else 1
*/
static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
static int convert_params(size_t cnt, char **params,
mbedtls_test_argument_t *int_params_store)
{
char **cur = params;
char **out = params;
@ -221,7 +222,7 @@ static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
break;
}
} else if (strcmp(type, "int") == 0) {
if (verify_int(val, int_params_store) == 0) {
if (verify_int(val, &int_params_store->s32) == 0) {
*out++ = (char *) int_params_store++;
} else {
ret = (DISPATCH_INVALID_TEST_DATA);
@ -235,7 +236,7 @@ static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
mbedtls_test_unhexify((unsigned char *) val, strlen(val),
val, &len) == 0);
*int_params_store = len;
int_params_store->len = len;
*out++ = val;
*out++ = (char *) (int_params_store++);
} else {
@ -244,7 +245,7 @@ static int convert_params(size_t cnt, char **params, int32_t *int_params_store)
}
} else if (strcmp(type, "exp") == 0) {
int exp_id = strtol(val, NULL, 10);
if (get_expression(exp_id, int_params_store) == 0) {
if (get_expression(exp_id, &int_params_store->s32) == 0) {
*out++ = (char *) int_params_store++;
} else {
ret = (DISPATCH_INVALID_TEST_DATA);
@ -463,7 +464,7 @@ int execute_tests(int argc, const char **argv)
char buf[5000];
char *params[50];
/* Store for processed integer params. */
int32_t int_params[50];
mbedtls_test_argument_t int_params[50];
void *pointer;
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
int stdout_fd = -1;