]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sha1.c
pppd: Fix SIGSEGV in EAP-TLS code when TLS verify method is not specified
[ppp.git] / pppd / sha1.c
index da142f1a7611b67a31e0ba39da5c36c70de8c1d5..4e51cee506c237ce2385ad3ed94003e31c9f1914 100644 (file)
@@ -17,7 +17,9 @@
 /* #define SHA1HANDSOFF * Copies data before messing with it. */
 
 #include <string.h>
+#include <time.h>
 #include <netinet/in.h>        /* htonl() */
+#include <net/ppp_defs.h>
 #include "sha1.h"
 
 static void
@@ -121,18 +123,17 @@ SHA1_Update(SHA1_CTX *context, const unsigned char *data, unsigned int len)
     j = (context->count[0] >> 3) & 63;
     if ((context->count[0] += len << 3) < (len << 3)) context->count[1]++;
     context->count[1] += (len >> 29);
-    if ((j + len) > 63) {
-       memcpy(&context->buffer[j], data, (i = 64-j));
+    i = 64 - j;
+    while (len >= i) {
+       memcpy(&context->buffer[j], data, i);
        SHA1_Transform(context->state, context->buffer);
-       for ( ; i + 63 < len; i += 64) {
-           SHA1_Transform(context->state, &data[i]);
-       }
+       data += i;
+       len -= i;
+       i = 64;
        j = 0;
     }
-    else
-       i = 0;
 
-    memcpy(&context->buffer[j], &data[i], len - i);
+    memcpy(&context->buffer[j], data, len);
 }