summarylogtreecommitdiffstats
path: root/0001-telnetd-Fix-buffer-overflows.patch
blob: b3f8654b3b4423a64ede674dd63818bf3ae6b97d (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From c4f1bc8e2e9e6303a33e1babfffafef9aa628c49 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Tue, 11 Jul 2017 12:22:41 +0200
Subject: [PATCH] telnetd: Fix buffer overflows

Increate the data buffers so that the terminating NUL fits. Use strlen
instead of sizeof to cope with the buffers size increase and to make
the code future-proof.
---
 ChangeLog          |  7 +++++++
 telnetd/telnetd.c  |  6 +++---
 telnetd/termstat.c | 34 +++++++++++++++++-----------------
 3 files changed, 27 insertions(+), 20 deletions(-)

# changelog patch elimianted. It interferes with all future versions.
#diff --git a/ChangeLog b/ChangeLog
#index ea93a846..99157ea1 100644
#--- a/ChangeLog
#+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-07-11  Guillem Jover  <guillem@hadrons.org>
+
+	* telnetd/telnetd.c (telnetd_run): Increate the data buffer so that
+	the terminating NUL fits. Use strlen instead of sizeof to cope with
+	the buffer size increase and make the code future-proof.
+	* telnetd/termstat.c (localstat, flowstat, clientstat): Likewise.
+
 2017-07-10  Omer Anson <oaanson@gmail.com>  (tiny change)
 
 	* src/hostname.c (parse_file): Free name and allocate one extra
diff --git a/telnetd/telnetd.c b/telnetd/telnetd.c
index 5e13e23d..917a3355 100644
--- a/telnetd/telnetd.c
+++ b/telnetd/telnetd.c
@@ -706,15 +706,15 @@ telnetd_run (void)
 	      int newflow = (c & TIOCPKT_DOSTOP) ? 1 : 0;
 	      if (newflow != flowmode)
 		{
-		  char data[6];
+		  char data[7];
 
 		  sprintf (data, "%c%c%c%c%c%c",
 			   IAC, SB, TELOPT_LFLOW,
 			   flowmode ? LFLOW_ON : LFLOW_OFF,
 			   IAC, SE);
-		  net_output_datalen (data, sizeof (data));
+		  net_output_datalen (data, strlen (data));
 		  DEBUG (debug_options, 1,
-			 printsub ('>', data + 2, sizeof (data) - 2));
+			 printsub ('>', data + 2, strlen (data) - 2));
 		}
 	    }
 
diff --git a/telnetd/termstat.c b/telnetd/termstat.c
index a3e37d03..167fff1e 100644
--- a/telnetd/termstat.c
+++ b/telnetd/termstat.c
@@ -306,7 +306,7 @@ localstat (void)
 	}
       else if (lmodetype == REAL_LINEMODE)
 	{
-	  char data[7];
+	  char data[8];
 
 	  send_do (TELOPT_LINEMODE, 1);
 	  /* send along edit modes */
@@ -314,9 +314,9 @@ localstat (void)
 		   IAC, SB, TELOPT_LINEMODE,
 		   LM_MODE, useeditmode,
 		   IAC, SE);
-	  net_output_datalen (data, sizeof (data));
+	  net_output_datalen (data, strlen (data));
 	  DEBUG (debug_options, 1,
-		 printsub ('>', data + 2, sizeof (data) - 2));
+		 printsub ('>', data + 2, strlen (data) - 2));
 
 	  editmode = useeditmode;
 	}
@@ -341,15 +341,15 @@ localstat (void)
 	  /*
 	   * Send along appropriate edit mode mask.
 	   */
-	  char data[7];
+	  char data[8];
 
 	  sprintf (data, "%c%c%c%c%c%c%c",
 		   IAC, SB, TELOPT_LINEMODE,
 		   LM_MODE, useeditmode,
 		   IAC, SE);
-	  net_output_datalen (data, sizeof (data));
+	  net_output_datalen (data, strlen (data));
 	  DEBUG (debug_options, 1,
-		 printsub ('>', data + 2, sizeof (data) - 2));
+		 printsub ('>', data + 2, strlen (data) - 2));
 
 	  editmode = useeditmode;
 	}
@@ -393,7 +393,7 @@ flowstat (void)
 {
   if (his_state_is_will (TELOPT_LFLOW))
     {
-      char data[6];
+      char data[7];
 
       if (tty_flowmode () != flowmode)
 	{
@@ -402,9 +402,9 @@ flowstat (void)
 		   IAC, SB, TELOPT_LFLOW,
 		   flowmode ? LFLOW_ON : LFLOW_OFF,
 		   IAC, SE);
-	  net_output_datalen (data, sizeof (data));
+	  net_output_datalen (data, strlen (data));
 	  DEBUG (debug_options, 1,
-		 printsub ('>', data + 2, sizeof (data) - 2));
+		 printsub ('>', data + 2, strlen (data) - 2));
 	}
       if (tty_restartany () != restartany)
 	{
@@ -413,9 +413,9 @@ flowstat (void)
 		   IAC, SB, TELOPT_LFLOW,
 		   restartany ? LFLOW_RESTART_ANY : LFLOW_RESTART_XON,
 		   IAC, SE);
-	  net_output_datalen (data, sizeof (data));
+	  net_output_datalen (data, strlen (data));
 	  DEBUG (debug_options, 1,
-		 printsub ('>', data + 2, sizeof (data) - 2));
+		 printsub ('>', data + 2, strlen (data) - 2));
 	}
     }
 }
@@ -478,7 +478,7 @@ clientstat (register int code, register int parm1, register int parm2)
 	  if (lmodetype == REAL_LINEMODE && uselinemode)
 	    if (uselinemode)
 	      {
-		char data[7];
+		char data[8];
 
 		useeditmode = 0;
 		if (tty_isediting ())
@@ -494,9 +494,9 @@ clientstat (register int code, register int parm1, register int parm2)
 			 IAC, SB, TELOPT_LINEMODE,
 			 LM_MODE, useeditmode,
 			 IAC, SE);
-		net_output_datalen (data, sizeof (data));
+		net_output_datalen (data, strlen (data));
 		DEBUG (debug_options, 1,
-		       printsub ('>', data + 2, sizeof (data) - 2));
+		       printsub ('>', data + 2, strlen (data) - 2));
 
 		editmode = useeditmode;
 	      }
@@ -555,15 +555,15 @@ clientstat (register int code, register int parm1, register int parm2)
 
 	    if (!ack)
 	      {
-		char data[7];
+		char data[8];
 
 		sprintf (data, "%c%c%c%c%c%c%c",
 			 IAC, SB, TELOPT_LINEMODE,
 			 LM_MODE, useeditmode | MODE_ACK,
 			 IAC, SE);
-		net_output_datalen (data, sizeof (data));
+		net_output_datalen (data, strlen (data));
 		DEBUG (debug_options, 1,
-		       printsub ('>', data + 2, sizeof (data) - 2));
+		       printsub ('>', data + 2, strlen (data) - 2));
 	      }
 
 	    editmode = useeditmode;
-- 
2.13.2