Avoid buffer underflow in evp_test.
[openssl.git] / test / evp_test.c
index 494a46b3183d475eb914d4e3db6b82fcfe284d3e..d924e3f6fcb801521fadd20ddf4271e5fa200a79 100644 (file)
 
 static void remove_space(char **pval)
 {
-    unsigned char *p = (unsigned char *)*pval;
+    unsigned char *p = (unsigned char *)*pval, *beginning;
 
     while (isspace(*p))
         p++;
 
-    *pval = (char *)p;
+    *pval = (char *)(beginning = p);
 
     p = p + strlen(*pval) - 1;
 
     /* Remove trailing space */
-    while (isspace(*p))
+    while (p >= beginning && isspace(*p))
         *p-- = 0;
 }