From be90fe073e6859c97cabeaf89c057820985edcf7 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 2 Feb 2024 14:38:40 +0100 Subject: [PATCH] tfm and integer: skip whitespace at end in radix read --- wolfcrypt/src/integer.c | 3 +++ wolfcrypt/src/tfm.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 21ae2353a..dadfeb4ee 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -5358,6 +5358,9 @@ int mp_read_radix (mp_int * a, const char *str, int radix) ++str; } + /* Skip whitespace at end of str */ + while (CharIsWhiteSpace(*str)) + ++str; /* if digit in isn't null term, then invalid character was found */ if (*str != '\0') { mp_zero (a); diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index ff895c8ac..65d92ffa1 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -6029,7 +6029,13 @@ static int fp_read_radix(fp_int *a, const char *str, int radix) } } if (y >= radix) { - return FP_VAL; + /* Check if whitespace at end of line */ + while (CharIsWhiteSpace(*str)) + ++str; + if (*str) + return FP_VAL; + else + break; } /* if the char was found in the map