diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2011-02-15 15:56:13 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2011-02-15 15:56:13 +0000 |
commit | fe082202c0f6bac6c7ba6c4e5e1ee16d2929b3d2 (patch) | |
tree | faf57ad3ad702002186252e9eae3bbf20ec36882 /fips | |
parent | fbc164ec2fcc4d8aa360b01876c1e4e6190c6d0b (diff) |
Ignore final '\n' when checking if hex line length is odd.
Diffstat (limited to 'fips')
-rw-r--r-- | fips/fips_utl.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/fips/fips_utl.h b/fips/fips_utl.h index 3b8100cafa..98cb5915a2 100644 --- a/fips/fips_utl.h +++ b/fips/fips_utl.h @@ -98,9 +98,16 @@ static void fips_set_error_print(void) int hex2bin(const char *in, unsigned char *out) { - int n1, n2; + int n1, n2, isodd = 0; unsigned char ch; + n1 = strlen(in); + if (in[n1 - 1] == '\n') + n1--; + + if (n1 & 1) + isodd = 1; + for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; ) { /* first byte */ if ((in[n1] >= '0') && (in[n1] <= '9')) @@ -120,7 +127,7 @@ int hex2bin(const char *in, unsigned char *out) * all digits valid hex and null terminated which is true for the * strings we pass. */ - if (n1 == 1 && strlen(in) & 1) + if (n1 == 1 && isodd) { out[n2++] = ch; continue; |