提交 fe082202 编写于 作者: D Dr. Stephen Henson

Ignore final '\n' when checking if hex line length is odd.

上级 fbc164ec
...@@ -98,9 +98,16 @@ static void fips_set_error_print(void) ...@@ -98,9 +98,16 @@ static void fips_set_error_print(void)
int hex2bin(const char *in, unsigned char *out) int hex2bin(const char *in, unsigned char *out)
{ {
int n1, n2; int n1, n2, isodd = 0;
unsigned char ch; 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' ; ) for (n1=0,n2=0 ; in[n1] && in[n1] != '\n' ; )
{ /* first byte */ { /* first byte */
if ((in[n1] >= '0') && (in[n1] <= '9')) if ((in[n1] >= '0') && (in[n1] <= '9'))
...@@ -120,7 +127,7 @@ int hex2bin(const char *in, unsigned char *out) ...@@ -120,7 +127,7 @@ int hex2bin(const char *in, unsigned char *out)
* all digits valid hex and null terminated which is true for the * all digits valid hex and null terminated which is true for the
* strings we pass. * strings we pass.
*/ */
if (n1 == 1 && strlen(in) & 1) if (n1 == 1 && isodd)
{ {
out[n2++] = ch; out[n2++] = ch;
continue; continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册