Bug 449358 - nscd breaks getservbyport()
Summary: nscd breaks getservbyport()
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc
Version: 9
Hardware: i386
OS: Linux
low
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-06-02 11:57 UTC by Roman Kagan
Modified: 2008-07-23 07:08 UTC (History)
0 users

Fixed In Version: 2.8-8
Clone Of:
Environment:
Last Closed: 2008-07-23 07:08:31 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
potential fix (untested) (663 bytes, patch)
2008-06-02 12:59 UTC, Roman Kagan
no flags Details | Diff

Description Roman Kagan 2008-06-02 11:57:10 UTC
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

Comment 1 Roman Kagan 2008-06-02 12:59:14 UTC
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().

Comment 2 Jakub Jelinek 2008-06-03 10:51:07 UTC
Thanks, looks correct, applied to CVS.

Comment 3 Jakub Jelinek 2008-06-15 22:42:21 UTC
Fixed in rawhide glibc and will be eventually backported.

Comment 4 Fedora Update System 2008-07-08 20:27:23 UTC
glibc-2.8-7 has been submitted as an update for Fedora 9

Comment 5 Fedora Update System 2008-07-23 07:08:21 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.