From 7b51097285ff6b74176c7624fbf51498b7b7415d Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 21 Jan 2020 16:32:12 +0000 Subject: fixed uriunescape possibly missing an escaped character that landed on a boundary between two reads. --- uriunescape.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/uriunescape.c b/uriunescape.c index 0a7ef5d..73ceabd 100644 --- a/uriunescape.c +++ b/uriunescape.c @@ -1,10 +1,16 @@ #include "uri.h" #include +#include int main(int argc,char *argv[]) { - int n; + int i; int len; - char buf[4096]; + + char doh[2]; + int hack=0; + + char buf[16]; + char buf2[16]; if(argc > 1) { for(argv++,argc--;argc;argc--,argv++) { len=uriunescape(*argv,*argv); @@ -12,10 +18,26 @@ int main(int argc,char *argv[]) { if(argc-1) write(1," ",1); } } else { - while((n=read(0,buf,sizeof(buf)-1)) > 0) { - buf[n]=0; - len=uriunescape(buf,buf); - write(1,buf,len); + while(fgets(buf+hack,sizeof(buf)-1-hack,stdin)) {//this is a bad idea. first chunk could end inside of a sequence we could decode. [first %] [09 second] + hack=0; + for(i=0;i<2;i++) {//2 being max length of a %XX thing. + if(buf[strlen(buf)-1-i] == '%') { + for(j=0;j