]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
base64: Try to avoid static analyzer warning (part 2)
authorJouni Malinen <j@w1.fi>
Sun, 7 Dec 2014 20:02:57 +0000 (22:02 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 8 Dec 2014 09:07:56 +0000 (11:07 +0200)
Shift right on unsigned char limits the value to 0..63 which is within
bounds for base64_table[]. Anyway, some static analyzers do not seem to
understand that. See if an otherwise unnecessary masking gets rid of
false warnings. (CID 62858)

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/base64.c

index 7366c30d3c5878c50cb52c2fad8e5ba5850bf701..d44f290e56849c872345a2c79d5b275ac6125a7b 100644 (file)
@@ -63,14 +63,14 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
        }
 
        if (end - in) {
-               *pos++ = base64_table[in[0] >> 2];
+               *pos++ = base64_table[(in[0] >> 2) & 0x3f];
                if (end - in == 1) {
-                       *pos++ = base64_table[(in[0] & 0x03) << 4];
+                       *pos++ = base64_table[((in[0] & 0x03) << 4) & 0x3f];
                        *pos++ = '=';
                } else {
-                       *pos++ = base64_table[((in[0] & 0x03) << 4) |
-                                             (in[1] >> 4)];
-                       *pos++ = base64_table[(in[1] & 0x0f) << 2];
+                       *pos++ = base64_table[(((in[0] & 0x03) << 4) |
+                                              (in[1] >> 4)) & 0x3f];
+                       *pos++ = base64_table[((in[1] & 0x0f) << 2) & 0x3f];
                }
                *pos++ = '=';
                line_len += 4;