Deleted Added
full compact
tftp-options.c (213099) tftp-options.c (246139)
1/*
2 * Copyright (C) 2008 Edwin Groothuis. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
1/*
2 * Copyright (C) 2008 Edwin Groothuis. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: head/libexec/tftpd/tftp-options.c 213099 2010-09-24 10:40:17Z marius $");
27__FBSDID("$FreeBSD: head/libexec/tftpd/tftp-options.c 246139 2013-01-31 00:02:36Z marius $");
28
29#include <sys/socket.h>
30#include <sys/types.h>
31#include <sys/sysctl.h>
32#include <sys/stat.h>
33
34#include <netinet/in.h>
35#include <arpa/tftp.h>

--- 58 unchanged lines hidden (view full) ---

94 options[OPT_TSIZE].o_reply =
95 strdup(options[OPT_TSIZE].o_request);
96 return (0);
97}
98
99int
100option_timeout(int peer)
101{
28
29#include <sys/socket.h>
30#include <sys/types.h>
31#include <sys/sysctl.h>
32#include <sys/stat.h>
33
34#include <netinet/in.h>
35#include <arpa/tftp.h>

--- 58 unchanged lines hidden (view full) ---

94 options[OPT_TSIZE].o_reply =
95 strdup(options[OPT_TSIZE].o_request);
96 return (0);
97}
98
99int
100option_timeout(int peer)
101{
102 int to;
102
103 if (options[OPT_TIMEOUT].o_request == NULL)
104 return (0);
105
103
104 if (options[OPT_TIMEOUT].o_request == NULL)
105 return (0);
106
106 int to = atoi(options[OPT_TIMEOUT].o_request);
107 to = atoi(options[OPT_TIMEOUT].o_request);
107 if (to < TIMEOUT_MIN || to > TIMEOUT_MAX) {
108 tftp_log(acting_as_client ? LOG_ERR : LOG_WARNING,
109 "Received bad value for timeout. "
108 if (to < TIMEOUT_MIN || to > TIMEOUT_MAX) {
109 tftp_log(acting_as_client ? LOG_ERR : LOG_WARNING,
110 "Received bad value for timeout. "
110 "Should be between %d and %d, received %s",
111 TIMEOUT_MIN, TIMEOUT_MAX);
111 "Should be between %d and %d, received %d",
112 TIMEOUT_MIN, TIMEOUT_MAX, to);
112 send_error(peer, EBADOP);
113 if (acting_as_client)
114 return (1);
115 exit(1);
116 } else {
117 timeoutpacket = to;
118 options[OPT_TIMEOUT].o_reply =
119 strdup(options[OPT_TIMEOUT].o_request);

--- 70 unchanged lines hidden (view full) ---

190 }
191 }
192
193 if (size > (int)maxdgram) {
194 if (acting_as_client) {
195 tftp_log(LOG_ERR,
196 "Invalid blocksize (%d bytes), "
197 "net.inet.udp.maxdgram sysctl limits it to "
113 send_error(peer, EBADOP);
114 if (acting_as_client)
115 return (1);
116 exit(1);
117 } else {
118 timeoutpacket = to;
119 options[OPT_TIMEOUT].o_reply =
120 strdup(options[OPT_TIMEOUT].o_request);

--- 70 unchanged lines hidden (view full) ---

191 }
192 }
193
194 if (size > (int)maxdgram) {
195 if (acting_as_client) {
196 tftp_log(LOG_ERR,
197 "Invalid blocksize (%d bytes), "
198 "net.inet.udp.maxdgram sysctl limits it to "
198 "%d bytes.\n", size, maxdgram);
199 "%ld bytes.\n", size, maxdgram);
199 send_error(peer, EBADOP);
200 return (1);
201 } else {
202 tftp_log(LOG_WARNING,
203 "Invalid blocksize (%d bytes), "
204 "net.inet.udp.maxdgram sysctl limits it to "
200 send_error(peer, EBADOP);
201 return (1);
202 } else {
203 tftp_log(LOG_WARNING,
204 "Invalid blocksize (%d bytes), "
205 "net.inet.udp.maxdgram sysctl limits it to "
205 "%d bytes.\n", size, maxdgram);
206 "%ld bytes.\n", size, maxdgram);
206 size = maxdgram;
207 /* No reason to return */
208 }
209 }
210
211 asprintf(&options[OPT_BLKSIZE].o_reply, "%d", size);
212 segsize = size;
213 pktsize = size + 4;

--- 38 unchanged lines hidden (view full) ---

252 }
253
254 if (size > (int)maxdgram) {
255 for (i = 0; sizes[i+1] != 0; i++) {
256 if ((int)maxdgram < sizes[i+1]) break;
257 }
258 tftp_log(LOG_INFO,
259 "Invalid blocksize2 (%d bytes), net.inet.udp.maxdgram "
207 size = maxdgram;
208 /* No reason to return */
209 }
210 }
211
212 asprintf(&options[OPT_BLKSIZE].o_reply, "%d", size);
213 segsize = size;
214 pktsize = size + 4;

--- 38 unchanged lines hidden (view full) ---

253 }
254
255 if (size > (int)maxdgram) {
256 for (i = 0; sizes[i+1] != 0; i++) {
257 if ((int)maxdgram < sizes[i+1]) break;
258 }
259 tftp_log(LOG_INFO,
260 "Invalid blocksize2 (%d bytes), net.inet.udp.maxdgram "
260 "sysctl limits it to %d bytes.\n", size, maxdgram);
261 "sysctl limits it to %ld bytes.\n", size, maxdgram);
261 size = sizes[i];
262 /* No need to return */
263 }
264
265 asprintf(&options[OPT_BLKSIZE2].o_reply, "%d", size);
266 segsize = size;
267 pktsize = size + 4;
268 if (debug&DEBUG_OPTIONS)

--- 119 unchanged lines hidden ---
262 size = sizes[i];
263 /* No need to return */
264 }
265
266 asprintf(&options[OPT_BLKSIZE2].o_reply, "%d", size);
267 segsize = size;
268 pktsize = size + 4;
269 if (debug&DEBUG_OPTIONS)

--- 119 unchanged lines hidden ---