]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Remove quadratic complexity from openvpn_base64_decode()
authorJann Horn <jann@thejh.net>
Wed, 16 Jul 2014 19:55:42 +0000 (21:55 +0200)
committerGert Doering <gert@greenie.muc.de>
Sun, 14 Sep 2014 18:51:38 +0000 (20:51 +0200)
Every four input characters, openvpn_base64_decode called token_decode,
which in turn called strlen() on the remaining input. This means that
base64 decoding in openvpn had quadratic complexity.

All we really need to know is whether the token is complete, so replace
the check to check just that, and make the complexity linear wrt the
input length.

Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <5408494D.7050407@fox-it.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9016
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/base64.c

index 6dc8479fd94c095594de0248b1b45fe8b43a0ded..258b258e20c74dfc2dd5408301081a173fb73302 100644 (file)
@@ -108,7 +108,7 @@ token_decode(const char *token)
     int i;
     unsigned int val = 0;
     int marker = 0;
-    if (strlen(token) < 4)
+    if (!token[0] || !token[1] || !token[2] || !token[3])
        return DECODE_ERROR;
     for (i = 0; i < 4; i++) {
        val *= 64;