Fix Base64 encoding for HTTP's basic auth.
authorTimothy B. Terriberry <tterribe@xiph.org>
Sun, 28 Apr 2013 06:33:11 +0000 (23:33 -0700)
committerTimothy B. Terriberry <tterribe@xiph.org>
Sun, 28 Apr 2013 06:33:11 +0000 (23:33 -0700)
I thought I had tested this before, but it was sufficiently broken
 that clearly I had not.

src/http.c

index 708d70a..b2e6663 100644 (file)
@@ -2036,15 +2036,15 @@ static char *op_base64_encode(char *_dst,const char *_src,int _len){
     s1=_src[3*i+1];
     s2=_src[3*i+2];
     _dst[4*i+0]=BASE64_TABLE[s0>>2];
-    _dst[4*i+1]=BASE64_TABLE[s0&3<<4|s1>>4];
-    _dst[4*i+2]=BASE64_TABLE[s1&15<<2|s2>>6];
+    _dst[4*i+1]=BASE64_TABLE[(s0&3)<<4|s1>>4];
+    _dst[4*i+2]=BASE64_TABLE[(s1&15)<<2|s2>>6];
     _dst[4*i+3]=BASE64_TABLE[s2&63];
   }
   _len-=3*i;
   if(_len==1){
     s0=_src[3*i+0];
     _dst[4*i+0]=BASE64_TABLE[s0>>2];
-    _dst[4*i+1]=BASE64_TABLE[s0&3<<4];
+    _dst[4*i+1]=BASE64_TABLE[(s0&3)<<4];
     _dst[4*i+2]='=';
     _dst[4*i+3]='=';
     i++;
@@ -2053,8 +2053,8 @@ static char *op_base64_encode(char *_dst,const char *_src,int _len){
     s0=_src[3*i+0];
     s1=_src[3*i+1];
     _dst[4*i+0]=BASE64_TABLE[s0>>2];
-    _dst[4*i+1]=BASE64_TABLE[s0&3<<4|s1>>4];
-    _dst[4*i+2]=BASE64_TABLE[s1&15<<2];
+    _dst[4*i+1]=BASE64_TABLE[(s0&3)<<4|s1>>4];
+    _dst[4*i+2]=BASE64_TABLE[(s1&15)<<2];
     _dst[4*i+3]='=';
     i++;
   }