In libcdaudio-0.99.6, cddb.c there is the line fprintf(stdout, "%*s\n", index, index, inbuffer); which is just wrong, and can (and has) caused segfaults. Fixed in patch to libcdaudio below, along with a couple of error checks - one of which did cause cdcd to display garbage instead of an error message. --- libcdaudio-0.99.6/source/cddb.c 2001-08-18 16:26:19.000000000 +0200 +++ libcdaudio-0.99.6-patched/source/cddb.c 2002-12-15 18:29:26.000000000 +0100 @@ -840,7 +840,7 @@ inbuffer[index] = inchar; } - fprintf(stdout, "%*s\n", index, index, inbuffer); + fprintf(stdout, "%*s\n", index, inbuffer); return index; } @@ -916,7 +916,7 @@ free(outbuffer); if(mode == CDDB_MODE_HTTP) - cddb_skip_http_header(sock); + if (cddb_skip_http_header(sock)<0) return -1; if((inbuffer = malloc(256)) == NULL) return -1; @@ -1160,11 +1160,13 @@ cddb_genre(entry->entry_genre), entry->entry_id); - send(sock, outbuffer, strlen(outbuffer), 0); + if (send(sock, outbuffer, strlen(outbuffer), 0)<0) + return -1; + free(outbuffer); if(mode == CDDB_MODE_HTTP) - cddb_skip_http_header(sock); + if (cddb_skip_http_header(sock)<0) return -1; if(cddb_read_token(sock, token) < 0) return -1;
- send(sock, outbuffer, strlen(outbuffer), 0); + if (send(sock, outbuffer, strlen(outbuffer), 0)<0) + return -1; + free(outbuffer); wouldnt it be better to save the return value, free the buffer, then check the return value ? as it is it looks like you just generated a memleak
Yes, you're perfectly correct! Could you pretend I got it right the first time? :)
could you please post said patch as an attachement ? when you post it as a comment the whitespace gets all screwed up making the patch invalid ...
Created attachment 6549 [details, diff] Fixes wrong fprintf() call, plus some error checks. Patch attached - hopefully without memleaks this time!
all set now, thx for the patch http://cvs.gentoo.org/cgi-bin/viewcvs.cgi/gentoo-x86/media-libs/libcdaudio/files/libcdaudio-0.99.6-sanity-checks.patch?rev=1.1&content-type=text/vnd.viewcvs-markup http://cvs.gentoo.org/cgi-bin/viewcvs.cgi/gentoo-x86/media-libs/libcdaudio/libcdaudio-0.99.6-r1.ebuild?rev=1.1&content-type=text/vnd.viewcvs-markup