1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
$NetBSD: patch-db,v 1.2 2011/07/03 20:16:00 dholland Exp $
- use modern C
--- server/socket.c~ 1998-01-08 14:59:17.000000000 -0500
+++ server/socket.c 2008-08-31 02:22:10.000000000 -0400
@@ -37,6 +37,9 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
@@ -84,7 +87,7 @@ socket_as_Xserver
if (!mkdir(X_UNIX_DIR, 0777))
chmod(X_UNIX_DIR, 0777);
- (void)sprintf(xpath, "%s%d", X_UNIX_PATH, display);
+ (void)snprintf(xpath, sizeof(xpath), "%s%d", X_UNIX_PATH, display);
rv = create_port(XPORT, X_TCP_PORT+display, xpath);
(void)umask(umsk);
@@ -111,7 +114,7 @@ socket_as_xmc
if (!mkdir(XMC_UNIX_DIR, 0777))
chmod(XMC_UNIX_DIR, 0777);
- (void)sprintf(xmcpath, "%s%d", XMC_UNIX_PATH, display);
+ (void)snprintf(xmcpath, sizeof(xmcpath), "%s%d", XMC_UNIX_PATH, display);
rv = create_port(XMCPORT, XMC_TCP_PORT-display, xmcpath);
(void)umask(umsk);
@@ -393,7 +396,7 @@ socket_as_client
case FamilyLocal:
#ifdef UNIXCONN
usock.sun_family = AF_UNIX;
- sprintf(usock.sun_path, "%s%d", X_UNIX_PATH, display);
+ snprintf(usock.sun_path, sizeof(usock.sun_path), "%s%d", X_UNIX_PATH, display);
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
return perr(-1, usock.sun_path);
sock = (struct sockaddr *)&usock;
|