diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-18 00:11:46 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-18 00:11:46 +0000 |
commit | 78c565653005192c4587fce1ccac6c441cea7ca6 (patch) | |
tree | 72ed12eb934d037ed12180205bcafe5fd7d0890c /networking/tftp.c | |
parent | e421b5ebf6b2484455ea36bb6c98deff685088e3 (diff) | |
download | busybox-w32-78c565653005192c4587fce1ccac6c441cea7ca6.tar.gz busybox-w32-78c565653005192c4587fce1ccac6c441cea7ca6.tar.bz2 busybox-w32-78c565653005192c4587fce1ccac6c441cea7ca6.zip |
tftpd: fix bugs spotted by Vladimir
Diffstat (limited to 'networking/tftp.c')
-rw-r--r-- | networking/tftp.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/networking/tftp.c b/networking/tftp.c index 23a24139b..25001c22c 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -16,7 +16,7 @@ | |||
16 | * | 16 | * |
17 | * utftp: Copyright (C) 1999 Uwe Ohse <uwe@ohse.de> | 17 | * utftp: Copyright (C) 1999 Uwe Ohse <uwe@ohse.de> |
18 | * | 18 | * |
19 | * tftpd added by Denys Vlasenko | 19 | * tftpd added by Denys Vlasenko & Vladimir Dronnikov |
20 | * | 20 | * |
21 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 21 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
22 | * ------------------------------------------------------------------------- */ | 22 | * ------------------------------------------------------------------------- */ |
@@ -145,9 +145,9 @@ static int tftp_protocol( | |||
145 | socket_fd = xsocket(peer_lsa->u.sa.sa_family, SOCK_DGRAM, 0); | 145 | socket_fd = xsocket(peer_lsa->u.sa.sa_family, SOCK_DGRAM, 0); |
146 | setsockopt_reuseaddr(socket_fd); | 146 | setsockopt_reuseaddr(socket_fd); |
147 | 147 | ||
148 | block_nr = 1; | ||
148 | if (!ENABLE_TFTP || our_lsa) { | 149 | if (!ENABLE_TFTP || our_lsa) { |
149 | /* tftpd */ | 150 | /* tftpd */ |
150 | block_nr = 0; | ||
151 | 151 | ||
152 | /* Create a socket which is: | 152 | /* Create a socket which is: |
153 | * 1. bound to IP:port peer sent 1st datagram to, | 153 | * 1. bound to IP:port peer sent 1st datagram to, |
@@ -158,9 +158,17 @@ static int tftp_protocol( | |||
158 | xbind(socket_fd, &our_lsa->u.sa, our_lsa->len); | 158 | xbind(socket_fd, &our_lsa->u.sa, our_lsa->len); |
159 | xconnect(socket_fd, &peer_lsa->u.sa, peer_lsa->len); | 159 | xconnect(socket_fd, &peer_lsa->u.sa, peer_lsa->len); |
160 | 160 | ||
161 | if (CMD_GET(cmd)) { | ||
162 | /* it's upload - we must ACK 1st packet (with filename) | ||
163 | * as if it's "block 0" */ | ||
164 | block_nr = 0; | ||
165 | } | ||
166 | |||
161 | #if ENABLE_FEATURE_TFTP_BLOCKSIZE | 167 | #if ENABLE_FEATURE_TFTP_BLOCKSIZE |
162 | if (blocksize != TFTP_BLOCKSIZE_DEFAULT) { | 168 | if (blocksize != TFTP_BLOCKSIZE_DEFAULT) { |
163 | /* Create and send OACK packet */ | 169 | /* Create and send OACK packet */ |
170 | /* block_nr is still 1, we expect ACK to (block_nr-1), | ||
171 | * that is, to "block 0" */ | ||
164 | opcode = TFTP_OACK; | 172 | opcode = TFTP_OACK; |
165 | cp = xbuf + 2; | 173 | cp = xbuf + 2; |
166 | goto add_blksize_opt; | 174 | goto add_blksize_opt; |
@@ -169,7 +177,6 @@ static int tftp_protocol( | |||
169 | #endif | 177 | #endif |
170 | } else { | 178 | } else { |
171 | /* tftp */ | 179 | /* tftp */ |
172 | block_nr = 1; | ||
173 | 180 | ||
174 | /* We can't (and don't really need to) bind the socket: | 181 | /* We can't (and don't really need to) bind the socket: |
175 | * we don't know from which local IP datagrams will be sent, | 182 | * we don't know from which local IP datagrams will be sent, |
@@ -288,6 +295,8 @@ static int tftp_protocol( | |||
288 | bb_perror_msg("read"); | 295 | bb_perror_msg("read"); |
289 | goto ret; | 296 | goto ret; |
290 | } | 297 | } |
298 | if (len < 4) /* too small? */ | ||
299 | goto recv_again; | ||
291 | goto process_pkt; | 300 | goto process_pkt; |
292 | case 0: | 301 | case 0: |
293 | retries--; | 302 | retries--; |