diff options
author | Alan Somers <asomers@FreeBSD.org> | 2018-08-22 23:31:27 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2018-08-22 23:31:27 +0000 |
commit | 76e8e459e49f02d7423a25472b9a5694394d35b9 (patch) | |
tree | 8c1f284a065c102d4d89c6020f73ebd9dbb9c825 /libexec/tftpd | |
parent | ad4c75f74ae4a9335016697e3ac2b906d8320c1b (diff) | |
download | src-76e8e459e49f02d7423a25472b9a5694394d35b9.tar.gz src-76e8e459e49f02d7423a25472b9a5694394d35b9.zip |
tftpd: Fix data corruption bug with netascii
Transferring files in netascii format requires, among other things,
translating all CR characters to a CR,NUL pair. tftpd does this correctly
except when the CR occurs as the last octet of a packet. In that case, it
erroneously drops the NUL which should be part of the following packet. The
bug was caused by using 0 as a sentinel value in a variable that could
legitimately hold 0. Fix it by switching the sentinel value to -1.
PR: 178055
Reported by: Richard <rsitze@gmail.com>
Reviewed by: cem
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D16853
Notes
Notes:
svn path=/head/; revision=338216
Diffstat (limited to 'libexec/tftpd')
-rw-r--r-- | libexec/tftpd/tftp-file.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/libexec/tftpd/tftp-file.c b/libexec/tftpd/tftp-file.c index 3e06f5df6edb..a8e7bcf9228b 100644 --- a/libexec/tftpd/tftp-file.c +++ b/libexec/tftpd/tftp-file.c @@ -110,10 +110,10 @@ convert_to_net(char *buffer, size_t count, int init) { size_t i; static size_t n = 0, in = 0; - static int newline = 0; + static int newline = -1; if (init) { - newline = 0; + newline = -1; n = 0; in = 0; return 0 ; @@ -124,9 +124,9 @@ convert_to_net(char *buffer, size_t count, int init) */ i = 0; - if (newline) { + if (newline != -1) { buffer[i++] = newline; - newline = 0; + newline = -1; } while (i < count) { @@ -161,7 +161,7 @@ convert_to_net(char *buffer, size_t count, int init) if (i > count) { /* - * Whoops... that isn't alllowed (but it will happen + * Whoops... that isn't allowed (but it will happen * when there is a CR or LF at the end of the buffer) */ newline = buffer[i-1]; |