From b33e45ff357b1a0c8eef205e2124b61304fde4b1 Mon Sep 17 00:00:00 2001 From: 0xdeadbeer Date: Tue, 3 Sep 2024 21:51:27 +0200 Subject: [PATCH] fix: header parsing --- README | 1 - tinyparser | Bin 75528 -> 75880 bytes tinyparser.c | 68 +++++++++++++++++++++++++++++++++++++-------------- tinyparser.h | 5 ++++ 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/README b/README index b2199d8..8ec32db 100644 --- a/README +++ b/README @@ -19,7 +19,6 @@ LEAKS TODO * headers table needs length fields - * refactor header parsing * implement tests * integrations with tinyproxy..? diff --git a/tinyparser b/tinyparser index 87609c2dde0f925cf9b2671bef775382bad68c3b..29d6abb2763088da4f0b66966f1a7c4ca29b6e67 100755 GIT binary patch delta 17967 zcmb_^d3;S*_xD-*oO6eaGRY*#4H=Qi7(~PnVxH$ALV_rQ#7r+@iWrg}bxlR7R_UOP zqH1i5YEd1uTC}RPLABbdYOC_D@4h!_AJ6mq@4X*cYwxw!T6>NA?Bqz6ozp7MYh`hw zGQ7P0^VX48MSez>f05+2($hIv>1p^Ft|Gj1Bu6!Ckf7RybA*&aDbS|~iZ&xN8o75;$jpM4nAJuB_!~A|OnYgeOb&RWO zDrFd?1=4;aMeAhj)Pf9)9%PhhK{Qy>KVf>HahKte#~mEXpmIR%BG_M~$5(n{m?Q)pP|j)N(QV z=jU^1G-a)ewzqt(Nl{c~t7|?jB%k9bl--8aoE^L@(kV7M!-=a+Ic6*{mj=V{>d)2; z=SXMdSK(=?Fh5o6FA;1q{;pLb!jg<-KCyJq*yD50ek$`iShGqq-^(h=tSrrZH*55H zIivGTxQpSDmf$EkRayFXRTUE-WEIbQpiFZ+P{p5{Z#u;vWVOh=Tj-+gsHQc@tSrgA zo>i(JOHh>3{ygelnN@NQ%HC(sO6-|ei|1WcrkSO#+fzz2ua;z9E@hE*S(I6MThA)a ztRyy~(tDqh*0Kop$f2$11`qFM)od_XZg4qk^v7ApuW4EIHaN3N1n=Gd@g>$@(#~># z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JV&KH~#DYJK^Zgpu+_Hz&Cbco|Up33ZR9WstO$h03Eofx}y@#l`FrZ`~x~AQAUm)^{L+f1A}BE!vFvP diff --git a/tinyparser.c b/tinyparser.c index e11afae..3a3df00 100644 --- a/tinyparser.c +++ b/tinyparser.c @@ -15,7 +15,7 @@ int ver_len = 0; struct nod *header_tree = NULL; struct nod *method_tree = NULL; -char **header_table = NULL; +struct point *header_table = NULL; int read_line(char **buffer, char **buffer_limit) { int diff = 0; @@ -36,26 +36,41 @@ int read_line(char **buffer, char **buffer_limit) { } int parse_header(char *offset, int len) { - int cursor = 0; + int key = 0; int ret = 0; - char *header_limit = offset+len; - char *sep = strchr(offset, ':'); - if (!sep) { + int diff = 0; + + char *cursor = offset; + char *cursor_lim = offset+len; + + // header title + char *htitle_lim = strchr(offset, ':'); + if (!htitle_lim) { + return -1; + } + if (htitle_lim > cursor_lim) { return -1; } - if (sep > header_limit) { + diff = htitle_lim-cursor; + ret = streencmp(header_tree, cursor, diff); + if (!ret) { return -1; } - int htitle_len = sep-offset; - ret = streencmp(header_tree, offset, htitle_len); - if (ret == 0) { - return -1; + key = ret; + cursor += diff; + + // white space and seperators + while (*cursor == ':' || *cursor == ' ') { + cursor++; } - char *hvalue = sep+1; - header_table[ret] = hvalue; + // header value + diff = cursor_lim-cursor; + + header_table[key].er = cursor; + header_table[key].len = diff; return 0; } @@ -143,11 +158,30 @@ int parse_request(char *buffer) { return 0; } +void debug_stats(void) { + fprintf(stderr, "\tstats:\n" + "\t\tmethod: %d\n" + "\t\turi : %.*s\n" + "\t\tver : %.*s\n", + method, uri_len, uri, ver_len, ver + ); + + fprintf(stdout, "\theaders:\n"); + for (int i = 0; i < header_count; i++) { + struct point *pnt = &header_table[i]; + if (!pnt->er) { + continue; + } + + fprintf(stdout, "\t\t%d: %.*s\n", i, pnt->len, pnt->er); + } +} + int main(void) { int ret; char *str = strdup(TEST_ONE); - header_table = (char **) calloc(header_count, sizeof(char *)); + header_table = (struct point *) calloc(header_count, sizeof(struct point)); if (!header_table) { fprintf(stderr, "Not enough dynamic memory\n"); return -1; @@ -183,12 +217,8 @@ int main(void) { return -1; } - fprintf(stderr, "[+] Finished parsing request\n" - " method: %d\n" - " uri : %.*s\n" - " ver : %.*s\n", - method, uri_len, uri, ver_len, ver - ); + fprintf(stdout, "++Successfully parsed data++\n"); + debug_stats(); frenod(method_tree); frenod(header_tree); diff --git a/tinyparser.h b/tinyparser.h index 0e54d21..e8d157d 100644 --- a/tinyparser.h +++ b/tinyparser.h @@ -140,4 +140,9 @@ enum headers { header_count }; +struct point { + char *er; + int len; +}; + #endif