mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-20 21:39:54 +00:00
Error out if a value is out of range
psa_status_t is currently a signed type where only non-negative values are used, which makes things a bit awkward. For now, non-negative values trigger an error. This code will need to be revised if we switch to using negative values as error codes.
This commit is contained in:
parent
182c2e9836
commit
265a171c52
@ -160,6 +160,7 @@ typedef enum {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
value_type type;
|
||||
unsigned long max;
|
||||
int i;
|
||||
|
||||
if (argc <= 1 ||
|
||||
@ -172,14 +173,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (!strcmp(argv[1], "error") || !strcmp(argv[1], "status")) {
|
||||
type = TYPE_STATUS;
|
||||
max = 0x7fffffff; /* hard-coded because psa_status_t is signed */
|
||||
} else if (!strcmp(argv[1], "alg") || !strcmp(argv[1], "algorithm")) {
|
||||
type = TYPE_ALGORITHM;
|
||||
max = (psa_algorithm_t)( -1 );
|
||||
} else if (!strcmp(argv[1], "curve") || !strcmp(argv[1], "ecc_curve")) {
|
||||
type = TYPE_ECC_CURVE;
|
||||
max = (psa_ecc_curve_t)( -1 );
|
||||
} else if (!strcmp(argv[1], "type") || !strcmp(argv[1], "key_type")) {
|
||||
type = TYPE_KEY_TYPE;
|
||||
max = (psa_key_type_t)( -1 );
|
||||
} else if (!strcmp(argv[1], "usage") || !strcmp(argv[1], "key_usage")) {
|
||||
type = TYPE_KEY_USAGE;
|
||||
max = (psa_key_usage_t)( -1 );
|
||||
} else {
|
||||
printf("Unknown type: %s\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
@ -193,6 +199,10 @@ int main(int argc, char *argv[])
|
||||
printf("Non-numeric value: %s\n", argv[i]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (value > max) {
|
||||
printf("Value out of range: %s\n", argv[i]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TYPE_STATUS:
|
||||
|
Loading…
x
Reference in New Issue
Block a user