pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

libcddb fails to work properly on big-endian systems



While porting the asunder cd ripper to NetBSD I discovered a problem with
libcddb on big-endian systems.

The libcddb code in the timeout_connect routine makes use of getsockopt to
check for connection errors and it uses a length variable of type_t rather than socklen_t. This produces a compilation warning on amd64 and sparc64 systems:

/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I../include -I../include -I/usr/include -O 2 -I/usr/include -Wall -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wunused -Wpointer-arith -Wwrite-st rings -Wnested-externs -Wno-sign-compare -MT cddb_net.lo -MD -MP -MF .deps/cddb_net.Tpo -c -o cddb_net.lo cddb_net.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I../include -O2 -Wall -Wchar-subscripts -Wmissing-prototypes -Wmissing-d eclarations -Wunused -Wpointer-arith -Wwrite-strings -Wnested-externs -Wno-sign-compare -MT cddb_net.lo -MD -MP -MF .deps
/cddb_net.Tpo -c cddb_net.c  -fPIC -DPIC -o .libs/cddb_net.o
cddb_net.c: In function 'timeout_connect':
cddb_net.c:328:17: warning: passing argument 5 of 'getsockopt' from incompatible pointer type /usr/include/sys/socket.h:618:5: note: expected '__socklen_t * __restrict__' but argument is of type 'size_t *' libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I../include -O2 -Wall -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wunused -Wpointer-arith -Wwrite-strings -Wnested-externs -Wno-sign-compare -MT cddb_net.lo -MD -MP -MF .deps/cddb_net.Tpo -c cddb_net.c -o cddb_net.o >/dev/null 2>&1
mv -f .deps/cddb_net.Tpo .deps/cddb_net.Plo

On i386 systems no warning is produced. The resulting code works fine on i383
and amd64 systems and calls to look up disks on the cddb database complete
correctly. On sparc64 systems a timeout occurs and the connection fails.

Looking at the cddb code it is clear the problem is due to the getsockopt call
on big-endian system failing to store a return value.

Patching the code to use type socklen_t instead of type_t seems to fix the
problem on sparc64 without any ill effects on i386/amd64 systems.

The effect can be seen with a simple test program:

dtyson(sun)dtyson$ cc -o cddbtest cddbtest.c -lcddb -L /usr/pkg/lib -I /usr/pkg/include
dtyson(sun)dtyson$ ./cddbtest
error: connection error
libcddb: error: connection error

After applying the fix, rebuilding libcddb and recompiling:

dtyson(sun)dtyson$ ./cddbtest
matches 8
Artist GENESIS Title Wind and wuthering
X Artist Genesis Title Wind & Wuthering [Definitive Edition Remaster]
X Artist Genesis Title Wind & Wuthering
X Artist Genesis Title Wind & Wuthering
X Artist Genesis Title Wind & Wuthering
X Artist Genesis Title Wind & Wuthering
X Artist Genesis Title Wind & Wuthering
X Artist Genesis Title Wind & Wuthering

The patch and updated distinfo:

/usr/pkgsrc/audio/libcddb/distinfo:

$NetBSD: distinfo,v 1.11 2009/07/26 17:36:25 drochner Exp $

SHA1 (libcddb-1.3.2.tar.bz2) = 2a7855918689692ff5ca3316d078a859d51959ce
RMD160 (libcddb-1.3.2.tar.bz2) = e38ed8c7dd5a9b4a5b2a1772a9e98f914872c397
Size (libcddb-1.3.2.tar.bz2) = 352909 bytes
SHA1 (patch-cddb_net) = 5a2ad30b92592b06ea59a41ebecf4aebc036f3dd

/usr/pkgsrc/audio/libcddb/patches/patch-cddb_net:

--- lib/cddb_net.c.orig     2009-03-01 03:28:07.000000000 +0000
+++ lib/cddb_net.c  2014-01-08 17:38:02.000000000 +0000
@@ -305,7 +305,7 @@
             int rv;
             fd_set wfds;
             struct timeval tv;
-            size_t l;
+            socklen_t l;

             /* set up select time out */
             tv.tv_sec = timeout;


Please can someone look at getting the fix pulled up

Cheers,
Dave

--
============================================
Phone: 07805784357
Open Source O/S: www.netbsd.org
Caving: http://www.wirralcavinggroup.org.uk
============================================



Home | Main Index | Thread Index | Old Index