@@ -323,44 +323,47 @@ static char decode_http_post(HashTable *ht, String data) {
323323return  '\0' ;
324324}
325325
326- static  char  decode_json_post (HashTable  * ht , char  * data ) {
326+ static  char  decode_json_post (HashTable  * ht , String  data ) {
327+ unsigned short  buf_count  =  0 ;
327328char  buffer [STR_MAX ];
328- char  * traveler  =  buffer , key [1024 ], value [1024 ];
329- unsigned short  cpy_index  =  0 ;
329+ String  traveler  =  buffer ;
330330
331331strncpy (buffer , data , STR_MAX );
332332
333- while  (* traveler  !=  '\0' ) {
334- for  (unsigned int   i  =  0 ; i  <  1024 ; i ++ ) {
335- key [i ] =  '\0' ;
336- value [i ] =  '\0' ;
337- }
333+ while  ((* traveler  !=  '\0' ) &&  (buf_count  <  STR_MAX )) {
334+ unsigned short  cpy_idx  =  0 ;
335+ char  key [STR_MAX ] =  "" , value [STR_MAX ] =  "" ;
336+ 
338337// Key 
339- while  ((* traveler  !=  '\"' ) &&  (* traveler  !=  '\0' )) { 
338+ while  ((* traveler  !=  '\"' ) &&  (* traveler  !=  '\0' )  &&  ( buf_count   <   STR_MAX )) 
340339traveler ++ ;
341- } 
342- if  (* traveler  ==  '\0' )
340+ 
341+ if  (( * traveler  ==  '\0' )  ||  ( buf_count   >   STR_MAX ) )
343342break ;
344343traveler ++ ;
345344
346- while  (* traveler  !=  '\"' ) {
347- key [cpy_index ] =  * traveler ;
345+ while  (( * traveler  !=  '\"' )  &&  ( buf_count   <   STR_MAX ) ) {
346+ key [cpy_idx ] =  * traveler ;
348347traveler ++ ;
349- cpy_index ++ ;
348+ cpy_idx ++ ;
350349}
351350traveler ++ ;
352- cpy_index  =  0 ;
351+ cpy_idx  =  0 ;
352+ 
353353// Value 
354- while  (* traveler  !=  '\"' )
354+ while  (( * traveler  !=  '\"' )  &&  ( buf_count   <   STR_MAX ) )
355355traveler ++ ;
356+ 
357+ if  ((* traveler  ==  '\0' ) ||  (buf_count  >  STR_MAX ))
358+ break ;
356359traveler ++ ;
357- while  (* traveler  !=  '\"' ) {
358- value [cpy_index ] =  * traveler ;
360+ 
361+ while  ((* traveler  !=  '\"' ) &&  (buf_count  <  STR_MAX )) {
362+ value [cpy_idx ] =  * traveler ;
359363traveler ++ ;
360- cpy_index ++ ;
364+ cpy_idx ++ ;
361365}
362366traveler ++ ;
363- cpy_index  =  0 ;
364367ht_insert (ht , key , value );
365368}
366369return  '\0' ;
@@ -437,7 +440,6 @@ static HashTable parse_post_request(const String msg) {
437440end ++ ;
438441start  =  end ; 
439442}
440- ht_print (data );
441443return  data ;
442444}
443445
@@ -755,23 +757,23 @@ int main(const int argc, String *const argv) {
755757
756758compute_flags (argc , argv , & _verbose_flag );
757759
758- parse_post_request (
759- "Host: 192.168.1.77:8888\n" 
760- "Connection: keep-alive\n" 
761- "Content-Length: 41\n" 
762- "Cache-Control: max-age=0\n" 
763- "Origin: http://192.168.1.77:8888\n" 
764- "Upgrade-Insecure-Requests: 1\n" 
765- "DNT: 1\n" 
766- "Content-Type: application/x-www-form-urlencoded\n" 
767- "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\n" 
768- "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\n" 
769- "Referer: http://192.168.1.77:8888/\n" 
770- "Accept-Encoding: gzip, deflate\n" 
771- "Accept-Language: en-US,en;q=0.9\n\n" 
772- "name=a%24aa&email=qqq%40ddd.com&pas%21sword=zzz\n" 
773- );
774- return  0 ;
760+ //  parse_post_request(
761+ //  "Host: 192.168.1.77:8888\n"
762+ //  "Connection: keep-alive\n"
763+ //  "Content-Length: 41\n"
764+ //  "Cache-Control: max-age=0\n"
765+ //  "Origin: http://192.168.1.77:8888\n"
766+ //  "Upgrade-Insecure-Requests: 1\n"
767+ //  "DNT: 1\n"
768+ //  "Content-Type: application/x-www-form-urlencoded\n"
769+ //  "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\n"
770+ //  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\n"
771+ //  "Referer: http://192.168.1.77:8888/\n"
772+ //  "Accept-Encoding: gzip, deflate\n"
773+ //  "Accept-Language: en-US,en;q=0.9\n\n"
774+ //  "name=a%24aa&email=qqq%40ddd.com&pas%21sword=zzz\n"
775+ //  );
776+ //  return 0;
775777if  (!is_valid_port ()) {
776778fprintf (stderr , RED  "Port Error: Invalid port %s\n"  RESET , _port );
777779exit (EXIT_FAILURE );
0 commit comments