htdig bug fix for you...


Alex Block (alex@yourbottomline.com)
Mon, 02 Feb 1998 15:35:27 -0500


Andrew,

We were experiencing problems with htdig while it searched a WebSTAR web
server (htdig was bombing on a site, returning a memory fault). The web
server was reporting the content type as:

Content-type:text/html

The htdig code expects there to be a space between the colon and the
"text/html". Because a space didn't exist, a NULL pointer was
passed to the mystrcasecmp() function, which caused the program to seg. fault.

To correct the problem, we made changes to strcasecmp.cc

I've attached a copy of the strcasecmp.cc file in case you wish to
integrate the mod into your next release, or forward it to the list.

Thanks,

//
// strcasecmp.cc
//
// Implementation of strcasecmp
//
#include "lib.h"
#include <ctype.h>

//*****************************************************************************
// int mystrcasecmp(char *str1, const char *str2)
//
int mystrcasecmp(char *str1, const char *str2)
{
    int rc = 0;

    if ( str1 && str2 )
    {
        while (*str1 &&
                *str2 &&
                tolower((unsigned char)*str1) == tolower((unsigned char)*str2))
        {
            str1++;
            str2++;
        }

        rc = tolower((unsigned char)*str1) - tolower((unsigned char)*str2);
    } else {
        if ( str1 )
        {
            rc = tolower((unsigned char)*str1);
        } else if ( str2 )
        {
            rc = -tolower((unsigned char)*str2);
        } /* end if */
    }

    return(rc);
}

//#define tolower(ch) (isupper(ch) ? (ch) + 'a' - 'A' : (ch))
//*****************************************************************************
// int mystrncasecmp(char *str1, const char *str2, int n)
//
int mystrncasecmp(char *str1, const char *str2, int n)
{
    int rc = 0;

    if ( str1 && str2 )
    {
        while (n &&
                *str1 &&
                *str2 &&
                tolower((unsigned char)*str1) == tolower((unsigned char)*str2))
        {
            str1++;
            str2++;
            n--;
        }
        rc = (n == 0 ? 0 :
                tolower((unsigned char)*str1) - tolower((unsigned char)*str2));
    } else {
        if ( str1 )
        {
            rc = tolower((unsigned char)*str1);
        } else if ( str2 )
        {
            rc = -tolower((unsigned char)*str2);
        } /* end if */
    } /* end if */

    return(rc);
}

//*****************************************************************************
// char *strdup(char *str)
//
char *strdup(char *str)
{
    char *p = new char[strlen(str) + 1];
    strcpy(p, str);
    return p;
}

//*****************************************************************************
// char *mystrcasestr(char *s, char *pattern)
//
char *
mystrcasestr(char *s, char *pattern)
{
    int length = strlen(pattern);

    while (*s)
    {
        if (mystrncasecmp(s, pattern, length) == 0)
            return s;
        s++;
    }
    return 0;
}

Alexander Block tel. 613-733-0048
MarketAccess Communications, Inc. e-mail: alex@yourbottomline.com

Discover how to market like an Internet Pro -- we guarantee it!
http://www.yourbottomline.com/internet_pro/
Instant details by e-mail mailto:marketing@yourbottomline.com



This archive was generated by hypermail 2.0b3 on Sat Jan 02 1999 - 16:25:41 PST