[BusyBox] RDATE function

Matt Kraai kraai at alumni.carnegiemellon.edu
Thu Sep 27 10:35:58 UTC 2001


On Thu, Sep 27, 2001 at 09:24:19AM -0700, Larry Doolittle wrote:
> >      if ((tserv = getservbyname("time", "tcp")) == NULL)   /* find port # */
> > -             perror_msg_and_die("time");
> > +             tserv->s_port = ntohl(37);
> 
> Looks like an instant null pointer dereference to me.
> Care to try again?  Maybe something like:
> 
> 	int tport = ntohl(37);   /* default if getservbyname fails */
> 	if ((tserv = getservbyname("time", "tcp")) != NULL)
> 		tport = tserv->s_port;
> 	// sockets happen
> 	s_in.sin_port = tport;
> ?

Close.  I also should have used htonl() instead of ntohl().  Could
you please try the following?

Matt

Index: rdate.c
===================================================================
RCS file: /var/cvs/busybox/rdate.c,v
retrieving revision 1.19
diff -u -r1.19 rdate.c
--- rdate.c	2001/07/30 14:43:20	1.19
+++ rdate.c	2001/09/27 16:34:15
@@ -46,16 +46,16 @@
 	int fd;
 
 	h = xgethostbyname(host);         /* get the IP addr */
+	memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
+
+	s_in.sin_port = htonl(37);		  /* find port # */
+	if ((tserv = getservbyname("time", "tcp")) != NULL)
+		s_in.sin_port = tserv->s_port;
 
-	if ((tserv = getservbyname("time", "tcp")) == NULL)   /* find port # */
-		perror_msg_and_die("time");
+	s_in.sin_family = AF_INET;
 
 	if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)    /* get net connection */
 		perror_msg_and_die("socket");
-
-	memcpy(&s_in.sin_addr, h->h_addr, sizeof(s_in.sin_addr));
-	s_in.sin_port= tserv->s_port;
-	s_in.sin_family = AF_INET;
 
 	if (connect(fd, (struct sockaddr *)&s_in, sizeof(s_in)) < 0)      /* connect to time server */
 		perror_msg_and_die("%s", host);





More information about the busybox mailing list