httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Terbush <ra...@zyzzyva.com>
Subject palloc() not working as expected...
Date Thu, 18 Apr 1996 19:50:15 GMT

I'm working on the following bit of code that should parse
the r->args string and return a linked list of attribute/value
structures.  I'm finding that if my attribute or value is
greater than 8 char in length, it will overflow the storage in
this structure.  If I use malloc() instead of palloc() it works
as expected.

Should I not expect palloc() to work this way?



typedef struct reqArgStruct {
    char *attr;
    char *value;
    struct reqArgStruct *next;
} reqArgList;

reqArgList *reqArgListHead;

reqArgList *
reqParseArgs (request_rec *r)
{
    int pos = 0;
    int length = 0;
    reqArgList *newArgList;
    reqArgList *ArgListHead = NULL;
    reqArgList *ArgListTail = NULL;
    
    length = strlen (r->args);

    while (pos != length)
    {
	int foundEq = 0;
	int foundAmp = 0;
	int start = pos;
	int len = 0;
	char *attr;
	char *value;

	while (pos != length)
	{
	    if (r->args[pos] == '=')
	    {
		foundEq = 1;
		pos++;
		break;
	    }
	    pos++;
	    len++;
	}
	if (!foundEq)
	    break;

	(char *)attr = (char *)pcalloc(r->pool, sizeof(len + 1));
	strncpy (attr, &r->args[start], len);
	attr[len] = '\0';
	
	start = pos;
	len = 0;
	while (pos != length)
	{
	    if (r->args[pos] == '&')
	    {
		foundAmp = 1;
		pos++;
		break;
	    }
	    pos++;
	    len++;
	}

	(char *)value = (char *)palloc(r->pool, sizeof(len + 1));
	strncpy (value, &r->args[start], len);
	value[len] = '\0';
	
	(reqArgList *)newArgList = (reqArgList *)pcalloc (r->pool, sizeof (reqArgList));
	
	newArgList->attr = pstrdup (r->pool, attr);
	newArgList->value = pstrdup (r->pool, value);
	newArgList->next = NULL;

	if (ArgListTail == NULL)
	{
	    ArgListHead = newArgList;
	    ArgListTail = newArgList;
	}
	else
	{
	    ArgListTail->next = newArgList;
	    ArgListTail = newArgList;
	}

	if (!foundAmp)
	    break;
    }

    return (ArgListHead);
}




Mime
View raw message