Deleted Added
full compact
tftp-io.c (302408) tftp-io.c (339051)
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: stable/11/libexec/tftpd/tftp-io.c 246139 2013-01-31 00:02:36Z marius $");
27__FBSDID("$FreeBSD: stable/11/libexec/tftpd/tftp-io.c 339051 2018-10-01 15:47:34Z asomers $");
28
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <sys/socket.h>
32
33#include <netinet/in.h>
34#include <arpa/tftp.h>
35#include <arpa/inet.h>
36
28
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <sys/socket.h>
32
33#include <netinet/in.h>
34#include <arpa/tftp.h>
35#include <arpa/inet.h>
36
37#include <assert.h>
37#include <errno.h>
38#include <setjmp.h>
39#include <signal.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <syslog.h>
44#include <unistd.h>

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

388receive_packet(int peer, char *data, int size, struct sockaddr_storage *from,
389 int thistimeout)
390{
391 struct tftphdr *pkt;
392 struct sockaddr_storage from_local;
393 struct sockaddr_storage *pfrom;
394 socklen_t fromlen;
395 int n;
38#include <errno.h>
39#include <setjmp.h>
40#include <signal.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <syslog.h>
45#include <unistd.h>

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

389receive_packet(int peer, char *data, int size, struct sockaddr_storage *from,
390 int thistimeout)
391{
392 struct tftphdr *pkt;
393 struct sockaddr_storage from_local;
394 struct sockaddr_storage *pfrom;
395 socklen_t fromlen;
396 int n;
396 static int waiting;
397 static int timed_out;
397
398 if (debug&DEBUG_PACKETS)
399 tftp_log(LOG_DEBUG,
400 "Waiting %d seconds for packet", timeoutpacket);
401
402 pkt = (struct tftphdr *)data;
403
398
399 if (debug&DEBUG_PACKETS)
400 tftp_log(LOG_DEBUG,
401 "Waiting %d seconds for packet", timeoutpacket);
402
403 pkt = (struct tftphdr *)data;
404
404 waiting = 0;
405 signal(SIGALRM, timeout);
405 signal(SIGALRM, timeout);
406 setjmp(timeoutbuf);
406 timed_out = setjmp(timeoutbuf);
407 alarm(thistimeout);
408
407 alarm(thistimeout);
408
409 if (waiting > 0) {
410 alarm(0);
411 return (RP_TIMEOUT);
412 }
413
414 if (waiting > 0) {
409 if (timed_out != 0) {
415 tftp_log(LOG_ERR, "receive_packet: timeout");
416 alarm(0);
417 return (RP_TIMEOUT);
418 }
419
410 tftp_log(LOG_ERR, "receive_packet: timeout");
411 alarm(0);
412 return (RP_TIMEOUT);
413 }
414
420 waiting++;
421 pfrom = (from == NULL) ? &from_local : from;
422 fromlen = sizeof(*pfrom);
423 n = recvfrom(peer, data, size, 0, (struct sockaddr *)pfrom, &fromlen);
424
425 alarm(0);
426
427 DROPPACKETn("receive_packet", RP_TIMEOUT);
428
429 if (n < 0) {
430 tftp_log(LOG_ERR, "receive_packet: timeout");
431 return (RP_TIMEOUT);
432 }
433
415 pfrom = (from == NULL) ? &from_local : from;
416 fromlen = sizeof(*pfrom);
417 n = recvfrom(peer, data, size, 0, (struct sockaddr *)pfrom, &fromlen);
418
419 alarm(0);
420
421 DROPPACKETn("receive_packet", RP_TIMEOUT);
422
423 if (n < 0) {
424 tftp_log(LOG_ERR, "receive_packet: timeout");
425 return (RP_TIMEOUT);
426 }
427
434 alarm(0);
435
436 if (n < 0) {
437 /* No idea what could have happened if it isn't a timeout */
438 tftp_log(LOG_ERR, "receive_packet: %s", strerror(errno));
439 return (RP_RECVFROM);
440 }
441 if (n < 4) {
442 tftp_log(LOG_ERR,
443 "receive_packet: packet too small (%d bytes)", n);

--- 32 unchanged lines hidden ---
428 if (n < 0) {
429 /* No idea what could have happened if it isn't a timeout */
430 tftp_log(LOG_ERR, "receive_packet: %s", strerror(errno));
431 return (RP_RECVFROM);
432 }
433 if (n < 4) {
434 tftp_log(LOG_ERR,
435 "receive_packet: packet too small (%d bytes)", n);

--- 32 unchanged lines hidden ---