Changeset View
Changeset View
Standalone View
Standalone View
libexec/tftpd/tftp-io.c
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | static struct errmsg { | ||||
{ EEXISTS, "File already exists" }, | { EEXISTS, "File already exists" }, | ||||
{ ENOUSER, "No such user" }, | { ENOUSER, "No such user" }, | ||||
{ EOPTNEG, "Option negotiation" }, | { EOPTNEG, "Option negotiation" }, | ||||
{ -1, NULL } | { -1, NULL } | ||||
}; | }; | ||||
#define DROPPACKET(s) \ | #define DROPPACKET(s) \ | ||||
if (packetdroppercentage != 0 && \ | if (packetdroppercentage != 0 && \ | ||||
random()%100 < packetdroppercentage) { \ | arc4random()%100 < packetdroppercentage) { \ | ||||
tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \ | tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \ | ||||
return; \ | return; \ | ||||
} | } | ||||
#define DROPPACKETn(s,n) \ | #define DROPPACKETn(s,n) \ | ||||
if (packetdroppercentage != 0 && \ | if (packetdroppercentage != 0 && \ | ||||
random()%100 < packetdroppercentage) { \ | arc4random()%100 < packetdroppercentage) { \ | ||||
markj: What's wrong with random() here? arc4random() is overkill for what this is doing. | |||||
Done Inline ActionsAgreed, this is solely to silence make analyze. I doubt this code ever gets used anyway, the option that enables it is undocumented and the test suite doesn't even glance in its direction. des: Agreed, this is solely to silence `make analyze`. I doubt this code ever gets used anyway, the… | |||||
tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \ | tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \ | ||||
return (n); \ | return (n); \ | ||||
} | } | ||||
const char * | const char * | ||||
errtomsg(int error) | errtomsg(int error) | ||||
{ | { | ||||
static char ebuf[40]; | static char ebuf[40]; | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | send_error(int peer, int error) | ||||
tp->th_code = htons((u_short)error); | tp->th_code = htons((u_short)error); | ||||
for (pe = errmsgs; pe->e_code >= 0; pe++) | for (pe = errmsgs; pe->e_code >= 0; pe++) | ||||
if (pe->e_code == error) | if (pe->e_code == error) | ||||
break; | break; | ||||
if (pe->e_code < 0) { | if (pe->e_code < 0) { | ||||
pe->e_msg = strerror(error - 100); | pe->e_msg = strerror(error - 100); | ||||
tp->th_code = EUNDEF; /* set 'undef' errorcode */ | tp->th_code = EUNDEF; /* set 'undef' errorcode */ | ||||
} | } | ||||
strcpy(tp->th_msg, pe->e_msg); | snprintf(tp->th_msg, MAXPKTSIZE - 4, "%s%n", pe->e_msg, &length); | ||||
length = strlen(pe->e_msg); | length += 5; /* header and terminator */ | ||||
tp->th_msg[length] = '\0'; | |||||
length += 5; | |||||
if (debug & DEBUG_PACKETS) | if (debug & DEBUG_PACKETS) | ||||
tftp_log(LOG_DEBUG, "Sending ERROR %d: %s", error, tp->th_msg); | tftp_log(LOG_DEBUG, "Sending ERROR %d: %s", error, tp->th_msg); | ||||
if (sendto(peer, buf, length, 0, | if (sendto(peer, buf, length, 0, | ||||
(struct sockaddr *)&peer_sock, peer_sock.ss_len) != length) | (struct sockaddr *)&peer_sock, peer_sock.ss_len) != length) | ||||
tftp_log(LOG_ERR, "send_error: %s", strerror(errno)); | tftp_log(LOG_ERR, "send_error: %s", strerror(errno)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | send_ack(int fp, uint16_t block) | ||||
char buf[MAXPKTSIZE]; | char buf[MAXPKTSIZE]; | ||||
if (debug & DEBUG_PACKETS) | if (debug & DEBUG_PACKETS) | ||||
tftp_log(LOG_DEBUG, "Sending ACK for block %d", block); | tftp_log(LOG_DEBUG, "Sending ACK for block %d", block); | ||||
DROPPACKETn("send_ack", 0); | DROPPACKETn("send_ack", 0); | ||||
tp = (struct tftphdr *)buf; | tp = (struct tftphdr *)buf; | ||||
size = sizeof(buf) - 2; | |||||
tp->th_opcode = htons((u_short)ACK); | tp->th_opcode = htons((u_short)ACK); | ||||
tp->th_block = htons((u_short)block); | tp->th_block = htons((u_short)block); | ||||
size = 4; | size = 4; | ||||
if (sendto(fp, buf, size, 0, | if (sendto(fp, buf, size, 0, | ||||
(struct sockaddr *)&peer_sock, peer_sock.ss_len) != size) { | (struct sockaddr *)&peer_sock, peer_sock.ss_len) != size) { | ||||
tftp_log(LOG_INFO, "send_ack: %s", strerror(errno)); | tftp_log(LOG_INFO, "send_ack: %s", strerror(errno)); | ||||
return (1); | return (1); | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |
What's wrong with random() here? arc4random() is overkill for what this is doing.