aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/telnetd.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/networking/telnetd.c b/networking/telnetd.c
index f04b32f9e..481c932db 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -157,19 +157,20 @@ remove_iacs(struct tsession *ts, int *pnum_totty)
157} 157}
158 158
159/* 159/*
160 * Converting single 0xff into double on output 160 * Converting single IAC into double on output
161 */ 161 */
162static size_t iac_safe_write(int fd, const char *buf, size_t count) 162static size_t iac_safe_write(int fd, const char *buf, size_t count)
163{ 163{
164 const char *oxff; 164 const char *IACptr;
165 size_t wr, rc, total; 165 size_t wr, rc, total;
166 166
167 total = 0; 167 total = 0;
168 while (1) { 168 while (1) {
169 if (count == 0) 169 if (count == 0)
170 return total; 170 return total;
171 if (*buf == (char)0xff) { 171 if (*buf == (char)IAC) {
172 rc = safe_write(fd, "\xff\xff", 2); 172 static const char IACIAC[] ALIGN1 = { IAC, IAC };
173 rc = safe_write(fd, IACIAC, 2);
173 if (rc != 2) 174 if (rc != 2)
174 break; 175 break;
175 buf++; 176 buf++;
@@ -177,11 +178,11 @@ static size_t iac_safe_write(int fd, const char *buf, size_t count)
177 count--; 178 count--;
178 continue; 179 continue;
179 } 180 }
180 /* count != 0, *buf != 0xff */ 181 /* count != 0, *buf != IAC */
181 oxff = memchr(buf, 0xff, count); 182 IACptr = memchr(buf, IAC, count);
182 wr = count; 183 wr = count;
183 if (oxff) 184 if (IACptr)
184 wr = oxff - buf; 185 wr = IACptr - buf;
185 rc = safe_write(fd, buf, wr); 186 rc = safe_write(fd, buf, wr);
186 if (rc != wr) 187 if (rc != wr)
187 break; 188 break;
@@ -255,9 +256,13 @@ make_new_session(
255 //memcpy(TS_BUF2, iacs_to_send, sizeof(iacs_to_send)); 256 //memcpy(TS_BUF2, iacs_to_send, sizeof(iacs_to_send));
256 //ts->rdidx2 = sizeof(iacs_to_send); 257 //ts->rdidx2 = sizeof(iacs_to_send);
257 //ts->size2 = sizeof(iacs_to_send); 258 //ts->size2 = sizeof(iacs_to_send);
258 /* So just stuff it into TCP buffer! */ 259 /* So just stuff it into TCP stream! (no error check...) */
260#if ENABLE_FEATURE_TELNETD_STANDALONE
259 safe_write(sock, iacs_to_send, sizeof(iacs_to_send)); 261 safe_write(sock, iacs_to_send, sizeof(iacs_to_send));
260 /*ts->rdidx2 = 0; - xzalloc did it! */ 262#else
263 safe_write(1, iacs_to_send, sizeof(iacs_to_send));
264#endif
265 /*ts->rdidx2 = 0; - xzalloc did it */
261 /*ts->size2 = 0;*/ 266 /*ts->size2 = 0;*/
262 } 267 }
263 268