diff options
author | epoch <epoch@hack.thebackupbox.net> | 2020-01-21 16:32:12 +0000 |
---|---|---|
committer | epoch <epoch@hack.thebackupbox.net> | 2020-01-21 16:32:12 +0000 |
commit | 7b51097285ff6b74176c7624fbf51498b7b7415d (patch) | |
tree | e8688d7078cb6c32c0546de71ce54e64f1d34c41 /uriunescape.c | |
parent | 92de12317383f25c0f93ae683530cce5024a0ffc (diff) | |
download | uritools-7b51097285ff6b74176c7624fbf51498b7b7415d.tar.gz uritools-7b51097285ff6b74176c7624fbf51498b7b7415d.zip |
fixed uriunescape possibly missing an escaped character that landed on a boundary between two reads.
Diffstat (limited to 'uriunescape.c')
-rw-r--r-- | uriunescape.c | 34 |
1 files 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 <unistd.h> +#include <stdio.h> 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<i;j++) { + doh[j] = buf[strlen(buf)-1-j];//save it for when we need to fix it back. + } + buf[strlen(buf)-1-i] = 0;//zero out the % + hack=2; + len=uriunescape(buf,buf2); + write(1,buf2,len); + //we end with a %[single char] + buf[0]='%'; + buf[1]=doh; + } + } + if(!hack) {//we're good. + len=uriunescape(buf,buf2); + write(1,buf2,len); + } } } return 0; |