Re: [PATCH]: Sending HTTP_BAD_REQUEST to client in case of bad request

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi,

no go with your patch. http_send_reply is a queuing function. that means 
when response could not be sent at once (e.g. client too slow) response 
sending will be registered (queued) in fdset. but in your patch you will 
destroy httpclient with goto error statement.

You should split http_send_reply function in a helper function which 
just prepare response and main function that send response queued as 
earlier. Then here instead of sending through http_send_reply you do 
something like:

Octstr *resp = http_prepare_reply(...)
conn_send(resp);
goto error;

Thanks,
Alex

Dziugas Baltrunas schrieb:
> Hi list,
> 
> in case of client sends us malformed URL (such as 
> /cgi-bin/sendsms?user=test&pass=test&to=12345 &text=test), attached
> patch sends a HTTP 400 Bad request error instead of simply closing the
> socket thus giving no indication to the client.
> 
> --
> Dziugas
> 
> 
> ------------------------------------------------------------------------
> 
> Index: gwlib/http.c
> ===================================================================
> RCS file: /home/cvs/gateway/gwlib/http.c,v
> retrieving revision 1.240
> diff -u -r1.240 http.c
> --- gwlib/http.c	5 Mar 2006 14:37:26 -0000	1.240
> +++ gwlib/http.c	22 Mar 2006 11:03:25 -0000
> @@ -2097,8 +2097,10 @@
>  	    ret = parse_request_line(&client->method, &client->url,
>                                       &client->use_version_1_0, line);
>  	    octstr_destroy(line);
> -	    if (ret == -1)
> -	    	goto error;
> +	    if (ret == -1) {
> +		http_send_reply(client, HTTP_BAD_REQUEST, NULL, NULL);
> +		goto error;
> +	    }
>     	    /*
>  	     * RFC2616 (4.3) says we should read a message body if there
>  	     * is one, even on GET requests.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.