From: Jann Horn Date: Wed, 16 Jul 2014 19:55:42 +0000 (+0200) Subject: Remove quadratic complexity from openvpn_base64_decode() X-Git-Tag: v2.4_alpha1~382 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25e1ec71dd150e803c0a25308c193fea124c7b7a;p=thirdparty%2Fopenvpn.git Remove quadratic complexity from openvpn_base64_decode() 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 Acked-by: Gert Doering Message-Id: <5408494D.7050407@fox-it.com> URL: http://article.gmane.org/gmane.network.openvpn.devel/9016 Signed-off-by: Gert Doering --- diff --git a/src/openvpn/base64.c b/src/openvpn/base64.c index 6dc8479fd..258b258e2 100644 --- a/src/openvpn/base64.c +++ b/src/openvpn/base64.c @@ -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;