broken strndup on AIX 5.1

William Jojo jojowil at hvcc.edu
Mon Aug 23 21:20:08 GMT 2004



If I can help here. I do not have the gcc used, but I ran these test
programs using the IBM compiler on 5.2 and the listed filesets described
below. It appears that strndup is fine, but strnlen returns questionable
results.


On Mon, 23 Aug 2004, Simo Sorce wrote:

>
> Hello Doug
> can you please split the code into 2 parts?
> I suspect both strnlen and strndup have similar bugs that are summing up
> by combinning them
> can you just strndup a string and print it, then strnlen it?
> this way we can see the bugs separately and maybe spot out a checkable
> pattern.
>
> Thanks,
> Simo.
>

I tested these on three AIX 5.2 systems with bos.rte.libc 5.2.0.31,
5.2.0.40 and 5.2.0.41 using C for AIX version 6:


Using:

#include <stdio.h>
#include <string.h>

main (int argc, char *argv[]) {
        int j,len;
        char namebuf[13] = "foobar";
        int jmax = strlen(namebuf)+1;

        for(j=0; j <jmax; j++) {
          len = strnlen(namebuf,j);
          printf("strndup(\"%s\",%d) =
%s\n",namebuf,j,strndup(namebuf,j));
        }
}


yielded:


[storage:/tmp] # ./strndup
strndup("foobar",0) =
strndup("foobar",1) = f
strndup("foobar",2) = fo
strndup("foobar",3) = foo
strndup("foobar",4) = foob
strndup("foobar",5) = fooba
strndup("foobar",6) = foobar


for strnlen:

using:

#include <stdio.h>
#include <string.h>

main (int argc, char *argv[]) {
        int j,len;
        char namebuf[13] = "foobar";
        int jmax = strlen(namebuf)+1;

        for(j=0; j <jmax; j++) {
          len = strnlen(namebuf,j);
          printf("strnlen(\"%s\",%d) = %d\n",namebuf,j,len);
        }
}


yields:

[storage:/tmp] # ./strnlen
strnlen("foobar",0) = 0
strnlen("foobar",1) = 3
strnlen("foobar",2) = 2
strnlen("foobar",3) = 1
strnlen("foobar",4) = 0
strnlen("foobar",5) = 6
strnlen("foobar",6) = 6



I do not have a 5.1 box any longer to test. :-(

I'm hoping this is helpful.


Bill


More information about the samba-technical mailing list