Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Jun 2002 21:51:40 -0400 (EDT)
From:      Charles Sprickman <spork@fasttrackmonkey.com>
To:        "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   porting from linux
Message-ID:  <Pine.OSX.4.44.0206122138090.3806-100000@white.nat.fasttrackmonkey.com>

next in thread | raw e-mail | index | archive | help
Hi,

I'm trying to track down a problem in the netsaint-plugins plugin
"check_snmp".  It partially works, but if check_snmp is given more than
one OID, it bombs out with a failure in "strscat".  Apparently "strscat"
comes from "utils.c" which is linked with "check_snmp.c".

The error generally looks like this:

bash-2.05a# /usr/local/libexec/netsaint/check_snmp -H localhost -C "" -o
.1.3.6.1.4.1.2021.10.1.5.1,.1.3.6.1.4.1.2021.10.1.5.2,.1.3.6.1.4.1.2021.10.1.5.3
-w :1,:2,:3 -c :5,:10,:20 -l load
check_snmp in free(): warning: chunk is already free
check_snmp in realloc(): warning: chunk is already free
failed malloc in strscat

I'm guessing that since netsaint is developed on Linux, I'm running into
some odd linux-ism.

I did a send-pr on the port and contacted the port maintainer, but I
thought maybe I'd find someone here who would like to tinker.  The port of
the netsaint-plugins is under /usr/ports/net.

FWIW, here's the strscat function in utils.c:

/******************************************************************************
 *
 * Concatenates one string to the end of another
 *
 * Given a pointer destination string, which may or may not already
 * hold some text, and a source string with additional text (possibly
 * NULL or empty), returns a pointer to a string that is the first
 * string with the second concatenated to it. Uses realloc to free
 * memory held by the dest argument if new storage space is required.
 *
 * Example:
 *
 * char *str=NULL;
 * str = strscpy("This is a line of text with no trailing newline");
 * str = strscat(str,"\n");
 *

*****************************************************************************/

char *strscat(char *dest, const char *src)
{
        int len,l2;

        if (src)
                l2 = strlen (src);
        else
                return dest;

        if (dest)
                len = strlen (dest);
        else
                len = 0;

        dest = realloc (dest, len + l2 + 1);
        if (dest == NULL)
                terminate (STATE_UNKNOWN, "failed malloc in strscat\n");

        strncpy (dest + len, src, l2);
        dest[len + l2] = 0;

        return dest;
}


And the call to strscat in check_snmp:

       while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process))
                output = strscat(output, input_buffer);

---
                        if (ptr && strstr(ptr, delimiter) == NULL) {
                                response = strscat(response, ptr);
                                ptr = NULL;
---

I'm not a C person at all.  I wish this had just been written in perl :)

FWIW, I found some general porting guidelines on the net, but most of them
in talking about free(), malloc(), and realloc() just mention that you
shouldn't be including malloc.h, and this does not.

Any help is appreciated.

PR is: http://www.freebsd.org/cgi/query-pr.cgi?pr=39182

port maintainer is: blaz@si.FreeBSD.org

Thanks for any help!

Charles





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.OSX.4.44.0206122138090.3806-100000>