Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Oct 1995 08:35:20 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        jc@irbs.com, terry@lambert.org
Cc:        freebsd-current@freefall.freebsd.org
Subject:   Re: phkmalloc and X programs
Message-ID:  <199510142235.IAA27701@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> Here is another broken X program.  Notice the assumption that
>> malloc() returns zeroed memory.
>> 
>> xhost.c:
>> 
>>     namelen = strlen(name);
>>     if ((lname = (char *)malloc(namelen)) == NULL) {
>>         fprintf (stderr, "%s: malloc bombed in change_host\n", ProgramName);
>>         exit (1);
>>     }
>>     for (i = 0; i < namelen; i++) {
>>         lname[i] = tolower(name[i]);
>>     }
>>     if (!strncmp("inet:", lname, 5)) {
>>     ...
>>     ...

>The only assumption in this code is that namelen is >= 5.

Nope.  Suppose lname is initially "INOT:" and name is "inet"

>There is no assumption of numm termination on the lname string implicit
>in the malloc; if there were, it would be "namelen = strlen(name) + 1;".

That may be why the author thought that termination was unnecessary.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510142235.IAA27701>