aboutsummaryrefslogtreecommitdiff
path: root/libexec/tftpd/tftp-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/tftpd/tftp-io.c')
-rw-r--r--libexec/tftpd/tftp-io.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/libexec/tftpd/tftp-io.c b/libexec/tftpd/tftp-io.c
index b5f39423fd60..aaacc9dd7f45 100644
--- a/libexec/tftpd/tftp-io.c
+++ b/libexec/tftpd/tftp-io.c
@@ -72,13 +72,13 @@ static struct errmsg {
#define DROPPACKET(s) \
if (packetdroppercentage != 0 && \
- random()%100 < packetdroppercentage) { \
+ arc4random()%100 < packetdroppercentage) { \
tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \
return; \
}
#define DROPPACKETn(s,n) \
if (packetdroppercentage != 0 && \
- random()%100 < packetdroppercentage) { \
+ arc4random()%100 < packetdroppercentage) { \
tftp_log(LOG_DEBUG, "Artificial packet drop in %s", s); \
return (n); \
}
@@ -157,10 +157,8 @@ send_error(int peer, int error)
pe->e_msg = strerror(error - 100);
tp->th_code = EUNDEF; /* set 'undef' errorcode */
}
- strcpy(tp->th_msg, pe->e_msg);
- length = strlen(pe->e_msg);
- tp->th_msg[length] = '\0';
- length += 5;
+ snprintf(tp->th_msg, MAXPKTSIZE - 4, "%s%n", pe->e_msg, &length);
+ length += 5; /* header and terminator */
if (debug & DEBUG_PACKETS)
tftp_log(LOG_DEBUG, "Sending ERROR %d: %s", error, tp->th_msg);
@@ -331,7 +329,6 @@ send_ack(int fp, uint16_t block)
DROPPACKETn("send_ack", 0);
tp = (struct tftphdr *)buf;
- size = sizeof(buf) - 2;
tp->th_opcode = htons((u_short)ACK);
tp->th_block = htons((u_short)block);
size = 4;