|
From: Peter K. <pk...@us...> - 2001-04-11 12:24:22
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
bt_misc.c 1.5 1.6=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
open_tcpsocket() no longer crashes if there is no colon in
the address string. Instead it terminates the program
(thanks to Salil Gokhale for finding this).
The diff of the modified file(s):
--- bt_misc.c 2001/04/04 10:43:04 1.5
+++ bt_misc.c 2001/04/11 12:24:22 1.6
@@ -119,8 +119,6 @@
client_sockfd =3D accept(server_sockfd,=20
(struct sockaddr *)&(client_address),
&client_len);
-=20=20=20=20
- return client_sockfd;
}
else
{
@@ -139,10 +137,10 @@
return -1;
}
=20
-
syslog(LOG_INFO, "Socket connected to %s\n", server_address.sun_path);
- return client_sockfd;
}
+
+ return client_sockfd;
}
=20
/* TCP socket */
@@ -161,11 +159,16 @@
=20=20=20
/*parse address string */
=20
- pos =3D strchr(addrstr, ':');
+ if (!(pos =3D strchr(addrstr, ':')))
+ {
+ fprintf(stderr, "Port argument missing!\n");
+ exit(1);
+ }
=20
/* copy ip address */
- memcpy(ipstr, addrstr, pos-addrstr);
- ipstr[pos-addrstr]=3D0; /* null term */
+ *pos =3D '\0';
+ strncpy(ipstr, addrstr, sizeof ipstr);
+ ipstr[sizeof ipstr - 1] =3D '\0';
=20
/* extract port number */
port =3D atoi(pos+1);
@@ -199,8 +202,6 @@
client_sockfd =3D accept(server_sockfd,
(struct sockaddr *)&(client_address),
&client_len);
-=20=20=20=20
- return client_sockfd;
}
else
{
@@ -223,9 +224,9 @@
perror("open_tcpsocket");
exit(1);
}
+ }
=20
return client_sockfd;
- }
}
=20
=20
|