X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=parser.c;h=0d1054ff29ae454f92474e6711e711549a4ab0e6;hp=aa11d8ed7355357dc2ec568c0f70b1cc85885fdf;hb=c7ad3b51358d0b7704e5670d973ad1a376caf4e1;hpb=b6c671fd90134d458ad4722ec3a99742bced1a34 diff --git a/parser.c b/parser.c index aa11d8e..0d1054f 100644 --- a/parser.c +++ b/parser.c @@ -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,26 +149,37 @@ 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 { while (*p==' ' || *p=='\t') p++; - assert(*p=='\n'); + v= *p++; assert(v=='\n'); } } } @@ -359,6 +370,7 @@ static int paa_message(const char **message_r) { /* Returned value is invalidated by repeated calls. */ static char *buildbuf; static int buildbuflen; + const char *usetext; int r, tl; @@ -373,9 +385,10 @@ static int paa_message(const char **message_r) { return tokv_error; } if (r == tokv_newline) break; - tl+= strlen(yytext); + usetext= r == tokv_lwsp ? " " : yytext; + tl+= strlen(usetext); if (makeroom(&buildbuf,&buildbuflen,tl)) return stringoverflow("message"); - strcat(buildbuf,yytext); + strcat(buildbuf,usetext); } *message_r= buildbuf; return 0; @@ -488,7 +501,7 @@ static int pf_service(int ptoken, char ***rvalues) { } static int pf_callinguser(int ptoken, char ***rvalues) { - return parm_usernameuid(rvalues,logname,request_mbuf.callinguid); + return parm_usernameuid(rvalues,loginname,request_mbuf.callinguid); } static int pf_serviceuser(int ptoken, char ***rvalues) { @@ -1078,8 +1091,14 @@ int df_includelookup(int dtoken) { } else { if (*p=='.') *q++= ':'; while ((c= *p++)) { - if (c=='/') { *q++= ':'; c='-'; } - else if (c==':') { *q++= ':'; } + if (c=='/') { + *q++= ':'; + c= '-'; + } else if (!((c >= '0' && c <= '9') || + (c >= 'a' && c <= 'z') || + c == '-' || c == '_')) { + *q++= ':'; + } *q++= c; } *q++= 0;