-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnc-3.2-owl-linux.diff
127 lines (117 loc) · 3.55 KB
/
nc-3.2-owl-linux.diff
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
diff -urN --show-c-function nc-3.2.orig/Makefile nc-3.2-owl-linux/Makefile
--- nc-3.2.orig/Makefile Thu Jan 1 00:00:00 1970
+++ nc-3.2-owl-linux/Makefile Wed Dec 25 22:31:20 2002
@@ -0,0 +1,2 @@
+all clean:
+ $(MAKE) -C usr.bin/nc $@
diff -urN --show-c-function nc-3.2.orig/usr.bin/nc/Makefile nc-3.2-owl-linux/usr.bin/nc/Makefile
--- nc-3.2.orig/usr.bin/nc/Makefile Sun Sep 2 18:45:41 2001
+++ nc-3.2-owl-linux/usr.bin/nc/Makefile Sun Dec 29 20:45:10 2002
@@ -1,6 +1,24 @@
# $OpenBSD: Makefile,v 1.6 2001/09/02 18:45:41 jakob Exp $
+CC = gcc
+LD = gcc
+RM = rm -f
+ifndef CFLAGS
+CFLAGS = -c -O2 -fomit-frame-pointer
+endif
+CFLAGS += -Wall -Dlint
+LDFLAGS = -s
+
PROG= nc
SRCS= netcat.c atomicio.c socks.c
-.include <bsd.prog.mk>
+all: $(PROG)
+
+$(PROG): $(SRCS:.c=.o)
+ $(LD) $(LDFLAGS) $+ $(LIBS) -o $@
+
+.c.o:
+ $(CC) $(CFLAGS) $< -o $@
+
+clean:
+ $(RM) $(PROG) $(SRCS:.c=.o)
diff -urN --show-c-function nc-3.2.orig/usr.bin/nc/netcat.c nc-3.2-owl-linux/usr.bin/nc/netcat.c
--- nc-3.2.orig/usr.bin/nc/netcat.c Fri Dec 13 19:53:45 2002
+++ nc-3.2-owl-linux/usr.bin/nc/netcat.c Sun Dec 29 20:50:35 2002
@@ -49,6 +49,7 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <time.h>
#ifndef SUN_LEN
#define SUN_LEN(su) \
@@ -148,6 +149,7 @@ main(int argc, char *argv[])
break;
case 'r':
rflag = 1;
+ srandom(time(NULL) + getpid());
break;
case 's':
sflag = optarg;
@@ -260,7 +262,7 @@ main(int argc, char *argv[])
if (family != AF_UNIX)
s = local_listen(host, uport, hints);
if (s < 0)
- err(1, NULL);
+ exit(1);
/*
* For UDP, we will use recvfrom() initially
* to wait for a caller, then use the regular
@@ -376,7 +378,12 @@ unix_connect(char *path)
memset(&sun, 0, sizeof(struct sockaddr_un));
sun.sun_family = AF_UNIX;
- strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
+ if (strlen(path) < sizeof(sun.sun_path)) {
+ strncat(sun.sun_path, path, sizeof(sun.sun_path));
+ } else {
+ errx(1, "Socket path too long");
+ }
+
if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
close(s);
return (-1);
@@ -399,8 +406,14 @@ unix_listen(char *path)
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
return (-1);
- strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
+ memset(&sun, 0, sizeof(struct sockaddr_un));
sun.sun_family = AF_UNIX;
+ if (strlen(path) < sizeof(sun.sun_path)) {
+ strncat(sun.sun_path, path, sizeof(sun.sun_path));
+ } else {
+ errx(1, "Socket path too long");
+ }
+
if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
close(s);
return (-1);
@@ -504,9 +517,9 @@ local_listen(char *host, char *port, str
res0->ai_protocol)) == 0)
continue;
- ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
if (ret == -1)
- err(1, NULL);
+ exit(1);
if (bind(s, (struct sockaddr *)res0->ai_addr,
res0->ai_addrlen) == 0)
@@ -666,7 +679,7 @@ build_ports(char *p)
char *c;
for (x = 0; x <= (hi - lo); x++) {
- y = (arc4random() & 0xFFFF) % (hi - lo);
+ y = (random() & 0xFFFF) % (hi - lo);
c = portlist[x];
portlist[x] = portlist[y];
portlist[y] = c;
diff -urN --show-c-function nc-3.2.orig/usr.bin/nc/socks.c nc-3.2-owl-linux/usr.bin/nc/socks.c
--- nc-3.2.orig/usr.bin/nc/socks.c Thu Feb 28 18:05:36 2002
+++ nc-3.2-owl-linux/usr.bin/nc/socks.c Sun Dec 29 20:41:39 2002
@@ -52,6 +52,9 @@
int remote_connect(char *, char *, struct addrinfo);
+typedef uint32_t in_addr_t;
+typedef uint16_t in_port_t;
+
static in_addr_t
decode_addr (const char *s)
{