Description of problem: When nscd is running, getservbyport() returns garbage. With stock /etc/services, it returns spr-itunes (0 port) for any query. With 0 port removed from /etc/services, it returns NULL for any query. Version-Release number of selected component (if applicable): glibc-2.8-3.i686 nscd-2.8-3.i386 setup-2.6.14-1.fc9.noarch How reproducible: always Steps to Reproduce: Use the following program: #include <netdb.h> #include <stdio.h> int main(int argc, char **argv) { struct servent *s; s = getservbyport(htons(atoi(argv[1])), argv[2]); if (s) printf("%s\n", s->s_name); else printf("port not found\n"); } Without nscd everything is fine: # service nscd stop Stopping nscd: [ OK ] # ./bug 25 tcp smtp # ./bug 7425 tcp port not found With nscd and 0 port in /etc/services (stock /etc/services from setup package): # awk '$2 == "0/tcp" {print}' /etc/services spr-itunes 0/tcp # Shirt Pocket netTunes spl-itunes 0/tcp # Shirt Pocket launchTunes # service nscd stop Stopping nscd: [FAILED] # rm -f /var/db/nscd/* # service nscd start Starting nscd: [ OK ] # ./bug 25 tcp spr-itunes # ./bug 7425 tcp spr-itunes With nscd and without 0 port in /etc/services: # awk '$2 != "0/tcp"' /etc/services > /etc/services.nozero # cat /etc/services.nozero > /etc/services # service nscd stop Stopping nscd: [FAILED] # rm -f /var/db/nscd/* # service nscd start Starting nscd: [ OK ] # ./bug 25 tcp port not found # ./bug 7425 tcp port not found
Created attachment 307357 [details] potential fix (untested) Seems like the problem is in __nscd_getservbyport_r(), where the port is converted to a string at the end of the buffer, but then the beginning of the buffer is passed down to nscd_getserv_r().
Thanks, looks correct, applied to CVS.
Fixed in rawhide glibc and will be eventually backported.
glibc-2.8-7 has been submitted as an update for Fedora 9
glibc-2.8-8 has been pushed to the Fedora 9 stable repository. If problems still persist, please make note of it in this bug report.