X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=parser.c;h=ad0829d6911ce669384b0c908e4d4e7b5851f7e2;hb=a4089e2b1d4e3f503f426189fc2d03e6fece2df5;hp=e73b4c5a56f97d6a927c03e416ffe29c3f786838;hpb=574777cfe5f60257117950ab6861cb6db87279fe;p=userv.git diff --git a/parser.c b/parser.c index e73b4c5..ad0829d 100644 --- a/parser.c +++ b/parser.c @@ -6,7 +6,7 @@ * about m4 quoting &c., but we have to #include it so that the C * objects from the lexer are available. * - * Copyright (C)1996-1997 Ian Jackson + * Copyright (C)1996-1999 Ian Jackson * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -139,7 +139,7 @@ static void freecharparray(char **array) { static int dequote(char *inplace) { char *p, *q, buf[4], *bep; int v; - + p=q=inplace; assert(*p++ = '"'); while (*p && *p != '"') { @@ -149,21 +149,32 @@ static int dequote(char *inplace) { case 'r': *q++= '\r'; continue; case 't': *q++= '\t'; continue; case 'x': - assert(buf[0]= *++p); assert(buf[1]= *++p); buf[2]= 0; - v= strtoul(buf,&bep,16); assert(bep == buf+2); - assert(!(v & ~0xff)); *q++= v; p++; continue; + p++; + if (!((buf[0]= *p++) && (buf[1]= *p++))) { + parseerrprint("quoted string ends inside \\x sequence"); + return tokv_error; + } + buf[2]= 0; + v= strtoul(buf,&bep,16); + if (bep != buf+2) { + parseerrprint("invalid \\ sequence \\x%s in quoted string",buf); + return tokv_error; + } + assert(!(v & ~0xff)); + *q++= v; + continue; default: if (isalpha(*p)) { parseerrprint("unknown \\ sequence \\%c in quoted string",*p); return tokv_error; } else if (isdigit(*p)) { - assert(buf[0]= *++p); assert(buf[1]= *++p); assert(buf[2]= *++p); + if (!((buf[0]= *p++) && (buf[1]= *p++) && (buf[2]= *p++))) abort(); buf[3]= 0; v= strtoul(buf,&bep,8); - if (bep != buf+3 || (v & ~0xff)); { + if (bep != buf+3 || (v & ~0xff)) { parseerrprint("invalid \\ sequence \\%s in quoted string",buf); return tokv_error; } - *q++= v; p++; continue; + *q++= v; continue; } else if (ispunct(*p)) { *q++= *p++; continue; } else {