summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornicm <>2010-02-27 00:58:56 +0000
committernicm <>2010-02-27 00:58:56 +0000
commiteb98df51d4533bcb55eec48a0547d0a3fd3780bc (patch)
tree91427a1fb7c152a521ea188b281bd2cc1c53c0e5 /src
parenta4c03f38471963bbfc0c47e51ffab2e5d54ca93f (diff)
downloadopenbsd-eb98df51d4533bcb55eec48a0547d0a3fd3780bc.tar.gz
openbsd-eb98df51d4533bcb55eec48a0547d0a3fd3780bc.tar.bz2
openbsd-eb98df51d4533bcb55eec48a0547d0a3fd3780bc.zip
Fix the atelnet() function, which was wrong in several ways.
Pointed out by obsd at happyjack.org, fix based on a diff from kili@. ok deraadt
Diffstat (limited to 'src')
-rw-r--r--src/usr.bin/nc/netcat.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index 17ffc8921f..508712388d 100644
--- a/src/usr.bin/nc/netcat.c
+++ b/src/usr.bin/nc/netcat.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: netcat.c,v 1.94 2009/10/08 15:56:46 mpf Exp $ */ 1/* $OpenBSD: netcat.c,v 1.95 2010/02/27 00:58:56 nicm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -683,27 +683,27 @@ atelnet(int nfd, unsigned char *buf, unsigned int size)
683 unsigned char *p, *end; 683 unsigned char *p, *end;
684 unsigned char obuf[4]; 684 unsigned char obuf[4];
685 685
686 end = buf + size; 686 if (size < 3)
687 obuf[0] = '\0'; 687 return;
688 end = buf + size - 2;
688 689
689 for (p = buf; p < end; p++) { 690 for (p = buf; p < end; p++) {
690 if (*p != IAC) 691 if (*p != IAC)
691 break; 692 continue;
692 693
693 obuf[0] = IAC; 694 obuf[0] = IAC;
694 p++; 695 p++;
695 if ((*p == WILL) || (*p == WONT)) 696 if ((*p == WILL) || (*p == WONT))
696 obuf[1] = DONT; 697 obuf[1] = DONT;
697 if ((*p == DO) || (*p == DONT)) 698 else if ((*p == DO) || (*p == DONT))
698 obuf[1] = WONT; 699 obuf[1] = WONT;
699 if (obuf) { 700 else
700 p++; 701 continue;
701 obuf[2] = *p; 702
702 obuf[3] = '\0'; 703 p++;
703 if (atomicio(vwrite, nfd, obuf, 3) != 3) 704 obuf[2] = *p;
704 warn("Write Error!"); 705 if (atomicio(vwrite, nfd, obuf, 3) != 3)
705 obuf[0] = '\0'; 706 warn("Write Error!");
706 }
707 } 707 }
708} 708}
709 709