A Simple Compatability Question

Andrew Bartlett abartlet at samba.org
Tue Feb 17 23:04:54 GMT 2004


On Fri, 2004-02-13 at 00:54, Heinrich Mislik wrote:
> On 12 Feb 2004, at 21:15, Andrew Bartlett wrote:
> 
> > > Samba compiles with -D_LINUX_SOURCE_COMPAT, this breaks malloc in 64-
> > > Bit mode. I configured with 'CFLAGS=-U_LINUX_SOURCE_COMPAT'.
> > 
> > Can you give me some more detail on that?
> 
> This is from /usr/include/stdlib.h (_ALL_SOURCE is defined)
> 
> #if defined(_ALL_SOURCE) && defined(_LINUX_SOURCE_COMPAT)
> #ifdef  _NO_PROTO
> extern void *__linux_malloc();
> extern void *__linux_realloc();
> extern void *__linux_calloc();
> extern void *__linux_valloc();
> #else
> extern void *__linux_malloc(size_t);
> extern void *__linux_realloc(void *, size_t);
> extern void *__linux_calloc(size_t, size_t);
> extern void *__linux_valloc(size_t);
> #endif
> 
> I couldn't find anything about __linux_malloc() but the following 
> documents that it is not suitable for 64 Bit:
> 
> # cat malloc_broken.c
> #include <stdlib.h>
> main()
> {
>     char *p = malloc(10);
>     printf("%p\n",p);
>     p[0] =0;
> }
> 
> # cc -q32 -D_LINUX_SOURCE_COMPAT malloc_broken.c
> # ./a.out
> 200004f8
> # cc -q64 -D_LINUX_SOURCE_COMPAT malloc_broken.c
> # ./a.out
> 100005f0
> Segmentation fault (core dumped)
> # cc -q64 malloc_broken.c
> # ./a.out
> 1100005f0
> 
> The 64-bit Pointer is truncated to 32 bit!

Ouch!  Now what confuses me is why that happens, the definitions you
quote above should not make that happen...

> > > configure finds strndup and strnlen, both are broken. I changed 
> > > config.h after configuration accordingly. Otherwise 'mangling method 
> > > = hash2' will not work under certain conditions.
> > 
> > Can you please define broken?  Is it that the prototypes are not
> > correctly defined, and therefore cast-to-int causes problems, or is it
> > something else?
> 
> # cat strnlen_broken.c
> #include <string.h>
> #include <stdlib.h>
> 
> main()
> {
>    char *s1 = "01234567891";
>    printf("strlen %d\n",strlen(s1));
>    printf("strnlen %d\n",strnlen(s1,10));
> }
> # cc strnlen_broken.c
> # ./a.out
> strlen 11
> strnlen 11
> 
> strnlen should return 10! 

That is indeed buggy.

> I couldn't find a short example of the wrong behavior of strndup. 
> When i insterted DEBUG befor and after strndup in the Samba code, I 
> saw that no '\0' is put on the end. So sometimes I saw remainings of 
> previously used strings after the duplicated string.  
> 
> > In both cases, can you write a configure test to fix it (either use our
> > internal strndup/strnlen, or include the right headers for the
> > prototype).
> 
> Not to sure about configure tests, but the above should help. 
>  
> Note that cc is IBMs "vac.C 5.0.2.6   C for AIX Compiler" on AIX 5.2.
> 
> After writing the previous mail I found another issue with AIX:
> 
> I tested CPANs Filesys::SmbClient and got "timeout connecting to ..." 
> when connecting to the same host with smbclient worked fine. The 
> reason is, that due to the way the CPAN module was linked, the 
> function msleep from AIX was used indstead of samba's msleep. From 
> AIX Documentaion: 
> 
>      #include <sys/mman.h>
> 
>      int msleep (Sem)
>      msemaphore * Sem;
>      Description
> 
>      The msleep subroutine puts a calling process to sleep when a
>      semaphore is busy.
> 
> The function immediatly returned with EFAULT and therefor the timeout 
> occurred much too early. Samba should use another name. Compiling 
> with -Dmsleep=smb_msleep solved it for me.

Ok, we need to make that sys_msleep I suppose.

Can you file critical bugs against all this in bugzilla, so we don't
miss them for the next release?  

Thanks,

Andrew Bartlett

-- 
Andrew Bartlett                                 abartlet at pcug.org.au
Manager, Authentication Subsystems, Samba Team  abartlet at samba.org
Student Network Administrator, Hawker College   abartlet at hawkerc.net
http://samba.org     http://build.samba.org     http://hawkerc.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.samba.org/archive/samba-technical/attachments/20040218/93c32ba5/attachment.bin


More information about the samba-technical mailing list