RE: squid rewriter in reverse proxy mode

From: KRATKY, Andrej <Andrej.KRATKY@dont-contact.us>
Date: Wed, 23 Oct 2002 10:41:42 +0200

Hello Henrik,

thank You for the help. Adjustment seems to be working now:

##############################################################
# client_side.c - clientRedirectDone
##############################################################

static void
clientRedirectDone(void *data, char *result)
{
    char new_log_uri[MAX_URL];
    clientHttpRequest *http = data;
    request_t *new_request = NULL;
    request_t *old_request = http->request;
    debug(33, 5) ("clientRedirectDone: '%s' result=%s\n", http->uri,
        result ? result : "NULL");
    assert(http->redirect_state == REDIRECT_PENDING);
    http->redirect_state = REDIRECT_DONE;
    if (result) {
        http_status status = atoi(result);
        if (status == 301 || status == 302) {
            char *t = result;
            if ((t = strchr(result, ':')) != NULL) {
                http->redirect.status = status;
                http->redirect.location = xstrdup(t + 1);
            } else {
                debug(33, 1) ("clientRedirectDone: bad input: %s\n", result);
            }
        }
// Hack to keep URL note in log not in outgoing URL
        if (NULL!=strstr(result,"|")) {
         strncpy(new_log_uri,http->log_uri,MAX_URL);
         strncat(new_log_uri,strstr(result,"|"),MAX_URL-strlen(new_log_uri));
         *strstr(result,"|")='\0';
         safe_free(http->log_uri);
         http->log_uri = xstrdup(new_log_uri);
        }
// Hack END [Andrej 23.10.2002]
        if (strcmp(result, http->uri))
            new_request = urlParse(old_request->method, result);
    }

Regards

Andrej

-----Original Message-----
From: Henrik Nordström [mailto:hno@squid-cache.org]
Sent: Tuesday, October 22, 2002 8:07 PM
To: KRATKY, Andrej
Cc: Squid Dev
Subject: Re: squid rewriter in reverse proxy mode

Signal 6 is segmentation violation. Most likely you are overwriting memory.

Yep.. you do not ensure there is sufficient space in log_uri. This is
allocated just large enought to fit the logged URL with no extra headroom for
later modifications of the string. Also you have broken the if (valid) code
flow.. (missing curly brakets)

The correct code for updating http->log_uri while processing a request reads

   safe_free(http->log_uri);
   http->log_uri = xstrdup(the_new_url);

And should be done in clientRedirectDone (client_side.c) where all the other
parsing of redirector results take place.

Regards
Henrik

KRATKY, Andrej wrote:
> Hello Henrik,
>
> as seen in devel.squid-cache.org, you are responsible for reverse proxy
> functionality enhancements. I am using squid in reverse proxy mode with own
> rewriter and need an enhancement which would add an info into access log
> from external rewriter program. So I would like to ask you kindly for a
> help.
>
> Example:
> - input URL (to externel rewriter): http://www.something.com/abcd.cgi?ab=1
> - output URL (from externel rewriter):
> http://www2.something.com/abcd.cgi?ab=1|my_additional_info
>
> The part starting from '|' should be together with input URL written into
> access log and output URL without part behind '|' should be requested from
> the given server (www2). The adjustment I added into redirector.c is
> coloured in added source.
>
> It seems to be working, but after few requests squid goes down with signal
> 6: Oct 22 16:48:50 ev2 squid[15893]: Squid Parent: child process 15895
> exited due to signal 6 Oct 22 16:48:53 ev2 squid[15893]: Squid Parent:
> child process 15934 started
>
> Would you have a minute to help me resolve this problem?
>
> Thanx for a reply
>
> With Best Regards
>
> Andrej Kratky
>
>
>
> ##############################################################
> # redirect.c - redirectHandleReply()
> ##############################################################
>
> static void
> redirectHandleReply(void *data, char *reply)
> {
> redirectStateData *r = data;
> int valid;
> char *t;
> debug(29, 5) ("redirectHandleRead: {%s}\n", reply ? reply : "<NULL>");
> if (reply) {
> if ((t = strchr(reply, ' ')))
> *t = '\0';
> if (*reply == '\0')
> reply = NULL;
> }
> valid = cbdataValid(r->data);
> cbdataUnlock(r->data);
>
> if (valid)
> // Hack to keep URL note in log not in outgoing URL
> if (NULL!=strstr(reply,"|")) {
> strncat(((clientHttpRequest
> *)(r->data))->log_uri,strstr(reply,"|"),(MAX_URL-5-strlen(((clientHttpReque
>st *)(r->data))->log_uri))); *strstr(reply,"|")='\0';
> }
> // Hack END [Andrej 21.10.2002]
> r->handler(r->data, reply);
> redirectStateFree(r);
> }
Received on Wed Oct 23 2002 - 02:44:31 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:17:00 MST