[MPlayer-dev-eng] http stream basic auth base64_encode() fix
Jeff D'Angelo
jcd+mplayer at psu.edu
Tue Mar 7 17:26:18 CET 2006
On Mon, 6 Mar 2006, Reimar Döffinger wrote:
> Hi,
> It's late so excuse any thinking-errors...
>
> > } else {
> > - // Terminate with Mime style '='
> > - *out = '=';
> > - outLen++;
> > -
> > - return outLen;
> > + // Pad with 0 to 2 '=' chars as needed
> > + if (outLen & 3)
> > + memset(out, '=', 4 - (outLen & 3) );
> > + return (outLen + 3) & ~3;
>
> Actually, IMHO memset is actually not a good idea in this case, I
> prefer your old patch in this regard.
> The real reason I posted my patch is because you do not check the maxlen
> value here and might be writing beyond the buffer.
Ahh I see it now. I was relying on the while( outLen<outMax ) loop to
keep things in check as that would run after the last encode set.
Rounding outLen down to be divisible by 4 should cover that.
> So I think the best solution would be your original patch + my
> maxlen &= ~3;
> line.
Ok, how's this attached patch look? I added a couple speed ups to my
original.
--
Jeff
> Greetings,
> Reimar Döffinger
>
> _______________________________________________
> MPlayer-dev-eng mailing list
> MPlayer-dev-eng at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
>
-------------- next part --------------
Index: http.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/http.c,v
retrieving revision 1.34
diff -u -r1.34 http.c
--- http.c 9 Feb 2006 14:07:57 -0000 1.34
+++ http.c 7 Mar 2006 16:21:49 -0000
@@ -659,7 +659,7 @@
int
base64_encode(const void *enc, int encLen, char *out, int outMax) {
- static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+ static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned char *encBuf;
int outLen;
@@ -670,6 +670,7 @@
outLen = 0;
bits = 0;
shift = 0;
+ outMax &= ~3;
while( outLen<outMax ) {
if( encLen>0 ) {
@@ -685,9 +686,12 @@
bits <<= 6 - shift;
shift = 6;
} else {
- // Terminate with Mime style '='
- *out = '=';
- outLen++;
+ // As per RFC 2045, section 6.8,
+ // pad output as necessary: 0 to 2 '=' chars.
+ while( outLen & 3 ){
+ *out++ = '=';
+ outLen++;
+ }
return outLen;
}
More information about the MPlayer-dev-eng
mailing list