error: partial base64 value left over

Peter Rathlev peter at rathlev.dk
Wed Jan 26 23:17:27 UTC 2011


On Wed, 2011-01-26 at 22:38 +0100, Peter Rathlev wrote:
> I'm thinking more in the line of parsing not "while something base64"
> but rather "until something non-base64". It seems peek_token() always
> returns with cfile->tval set to the token (courtesy of the inner
> get_raw_token()) in question, and parse_base64() already has the
> "from64" array to help.
> 
> I'll try and write something up around that.

I have a proposal now, see below. I'll try and wrap it up in a
description with examples and send it to dhcp-bugs. Unless someone
points out some obvious blunders of course. :-)

--- dhcp-4.2.0-P2/common/parse.c	2009-10-28 05:12:29.000000000 +0100
+++ dhcp-4.2.0-P2-bareword-base64-fix/common/parse.c	2011-01-27 00:05:02.249688886 +0100
@@ -1821,6 +1821,7 @@
 			   *t;
 	int cc = 0;
 	int terminated = 0;
+	int valid_base64;
 	
 	/* It's possible for a + or a / to cause a base64 quantity to be
 	   tokenized into more than one token, so we have to parse them all
@@ -1841,9 +1842,15 @@
 			bufs = t;
 		last = t;
 		token = peek_token (&val, (unsigned *)0, cfile);
+		valid_base64 = 1;
+		for (i = 0; val [i]; i++) {
+			if (val [i] < ' ' || val [i] > 'z') {
+				valid_base64 = 0;
+			} else if (from64 [ val[i] - ' ' ] > 63 && val [i] != '=') {
+				valid_base64 = 0;
+			}
+		}
-	} while (token == NUMBER_OR_NAME || token == NAME || token == EQUAL ||
-		 token == NUMBER || token == PLUS || token == SLASH ||
-		 token == STRING);
+	} while (valid_base64);
 
 	data -> len = cc;
 	data -> len = (data -> len * 3) / 4;



-- 
Peter





More information about the dhcp-users mailing list