From nobody Fri May 10 21:17:00 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VbhXY0dd7z5KRd7; Fri, 10 May 2024 21:17:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VbhXX5Qs5z4cS6; Fri, 10 May 2024 21:17:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715375820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oEVVqshSTaBePCyiHZBsUdxeJURaGIEFQFLYsL0IwRE=; b=pLasd8892FWrzT64z8D48Wjv8FqG/YegDD6kx6TqqsIYRSPLl2WiPN3IBW7GUv2GwLUoRC azT1p6FlNVkbA/fYsmykZlXOYnSIOhR0TPLsZq3sUBMQXBbjulO6vIAzszBFHJi2r+1t+v wRoC9GE0sSpOWAfboMeT7f2QFBL7vgl9YewQRKtW9Zq8biD03xmifH0ZnRb/rf85ggKu36 0nuzn464QTDkpcZwTjSHAWg0OhuhlS/WzeuHSRJk37qwM+SCk6CpphE3YRTAHIutvcjm2t MFeJwc/++ASD3VpiX9rRjxQ5DOGVznSttxbNP8HNF+OQIkEPs/AmpKUl8o+3vw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715375820; a=rsa-sha256; cv=none; b=oEXkv5RvK6ASBgT9y2pPQndoLeY9MyWRfnVhGLcAS0dbjZpoClWHSJMTzJfiLI76jugFvB Y41v6dc65PtAwVQGI8OKcFsYjPT5WLp7Hi2i3wGMaUU2qYTTdTn6cfYTEk57wFGQpCvVHa tp0OmJDbLnuC6miJxb0msldSNmrcHQmceUxAfNOvqb3uOICB7z/56wXCntfRn+PryyXsWN 754PidP1m1SHqQEfRAwsoqQV+WDa9T1L7pZiU9yrINkzmNvO0ExiYvgj1G9Z/ViQhW2aub Jb+U1dVqI+nvkfY6U58lAdnBa32YNy0to3bUH/oLgD4ChBkwZOQ9XBYqL4+rAw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715375820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=oEVVqshSTaBePCyiHZBsUdxeJURaGIEFQFLYsL0IwRE=; b=BTBVCujdpWXTcDzeoqguCY2B8MfqUNXwOmmPg9/sf+IoaTJA2M9U8rNrRyvOuT+LAk1CXY ck+L1AJep277ul+EEU7D9iwSTM2l1TACYaxT6vry+V7zh1LCEuqkSVkkQ6HW5LMSMEnoWX /PECH56OdQNNNRRbePtUow8FRwuCbgh1dn2DIcFUak91P9OzSeyitMRlWkE1yodJIs3R1W rAKzfaUZr1//k0fUguk+bGhOFDb4ofDaI8zJwHV/IzVM/Oz90oLJCco2idaWcT4xxQ91Ub qn+HhazFL24h1bGK5my9yuUjE+2SxAdkQQabfVY1fjXOwUS0XcZJ663nIh6tOQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VbhXX53BkztVw; Fri, 10 May 2024 21:17:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44ALH0gu082895; Fri, 10 May 2024 21:17:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44ALH0ef082892; Fri, 10 May 2024 21:17:00 GMT (envelope-from git) Date: Fri, 10 May 2024 21:17:00 GMT Message-Id: <202405102117.44ALH0ef082892@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 4d09eb87c5d5 - main - tftpd: Satisfy clang-analyzer. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4d09eb87c5d5bec2e2832f50537e2ce6f75f4117 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=4d09eb87c5d5bec2e2832f50537e2ce6f75f4117 commit 4d09eb87c5d5bec2e2832f50537e2ce6f75f4117 Author: Dag-Erling Smørgrav AuthorDate: 2024-05-10 21:15:49 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-10 21:16:26 +0000 tftpd: Satisfy clang-analyzer. * Replace `random()` with `arc4random()`. * Change some variable types. * Drop some unused assignments. MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: imp, markj Differential Revision: https://reviews.freebsd.org/D45132 --- libexec/tftpd/tftp-io.c | 11 ++++------- libexec/tftpd/tftp-utils.c | 2 +- libexec/tftpd/tftp-utils.h | 2 +- libexec/tftpd/tftpd.c | 13 ++++++------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/libexec/tftpd/tftp-io.c b/libexec/tftpd/tftp-io.c index d43e5f5505f9..50102e652d2f 100644 --- a/libexec/tftpd/tftp-io.c +++ b/libexec/tftpd/tftp-io.c @@ -71,13 +71,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); \ } @@ -156,10 +156,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); @@ -330,7 +328,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; diff --git a/libexec/tftpd/tftp-utils.c b/libexec/tftpd/tftp-utils.c index b309a94f7653..8ce7c09c9992 100644 --- a/libexec/tftpd/tftp-utils.c +++ b/libexec/tftpd/tftp-utils.c @@ -204,7 +204,7 @@ struct debugs debugs[] = { { DEBUG_ACCESS, "access", "TCPd access debugging" }, { DEBUG_NONE, NULL, "No debugging" }, }; -int packetdroppercentage = 0; +unsigned int packetdroppercentage = 0; int debug_find(char *s) diff --git a/libexec/tftpd/tftp-utils.h b/libexec/tftpd/tftp-utils.h index f87bbcccc71c..276dedcf74cd 100644 --- a/libexec/tftpd/tftp-utils.h +++ b/libexec/tftpd/tftp-utils.h @@ -99,7 +99,7 @@ struct debugs { }; extern int debug; extern struct debugs debugs[]; -extern int packetdroppercentage; +extern unsigned int packetdroppercentage; int debug_find(char *s); int debug_finds(char *s); const char *debug_show(int d); diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index c832097e0ba0..80497738f60d 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -160,7 +160,7 @@ main(int argc, char *argv[]) options_extra_enabled = 0; break; case 'p': - packetdroppercentage = atoi(optarg); + packetdroppercentage = (unsigned int)atoi(optarg); tftp_log(LOG_INFO, "Randomly dropping %d out of 100 packets", packetdroppercentage); @@ -451,9 +451,9 @@ static char * parse_header(int peer, char *recvbuffer, size_t size, char **filename, char **mode) { - char *cp; - int i; struct formats *pf; + char *cp; + size_t i; *mode = NULL; cp = recvbuffer; @@ -470,12 +470,11 @@ parse_header(int peer, char *recvbuffer, size_t size, i = get_field(peer, cp, size); *mode = cp; - cp += i; /* Find the file transfer mode */ - for (cp = *mode; *cp; cp++) - if (isupper(*cp)) - *cp = tolower(*cp); + for (; *cp; cp++) + if (isupper((unsigned char)*cp)) + *cp = tolower((unsigned char)*cp); for (pf = formats; pf->f_mode; pf++) if (strcmp(pf->f_mode, *mode) == 0) break;