From nobody Thu Apr 25 18:36:24 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 4VQPh83Xg9z5JJBJ; Thu, 25 Apr 2024 18:36:24 +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 4VQPh82p5Nz4YTR; Thu, 25 Apr 2024 18:36:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714070184; 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=RlU5vc89ZJ9riQpFAqceaGMi6PUwkjXcgXSb+iX4g9U=; b=cWyqZjY/ntn1H33Ahx4CkTlv/6BiFjOD3QJLXie0jYwT/EYGyuxZG5PPjhlGiLd6dzdSyh 79AYsuIPXGOfNTm9JS4YDUv88ho6lxX03kVO2wrxdDkGmb+/sGfwM7rgu3M3lgWsBkIAp5 RSnntIgslxpJUllCMQB1muEhHHES9c74ZsnjaWsqgrv/GaqtSu7eaCO4/AsnKWa5aHkBo/ ejzxo8NM0gKeFfqSZArWdBjY7fO+YKV/XJHJYedsYPLCbpyC/GuwfWYrJ3fR3t0dwW7ZZr wdmHEsJwjeEVLvwERyeIZs2QMc63cvpabIHiq3KKgyqZE2JxmXdCJLU+NnBMuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714070184; a=rsa-sha256; cv=none; b=OBkOB836fFqFaG1JGF4xTEkrFMHqbAP+SC6h+60w5d2HaRxMI4IenSFzeyIvSkdst9nPtJ 0DJMZsZ/BylsnmVZ/ogeBiQs6eA+eEknBZl3wB4DTXNMvBWe0qCjI0vp2Fb2rAmESmU+lL LxTlqjjVX90CkU8YSlyHv01Z9LzF6SF7rbq7j+/jbZX81fc0DL2fLLQ16yPPI7YtWGcryI 3DaMACqTBb0gLXRtDnYhDYxbf12c51HtLcWsla3KUI81yBxt5R3ZEf4bqjwyXsS89ydQdj in18E4F7BygSs3bioHn67DAsYdZcux/pI7af8MM8PBLeNr2Npj8M0ju+quM4UA== 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=1714070184; 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=RlU5vc89ZJ9riQpFAqceaGMi6PUwkjXcgXSb+iX4g9U=; b=aiJW+TqHJCrWEkZCfkSu9Q7PDe+nFk/E7d4B92bThU/tkRELX2oTSmRrqP8L3NPwkb4+VK iYSs/mmh3iRZlT64nmeScLsAz2RyjINeD+vJIk84tQ5KgmnxpeDe5j7Xr3G/LVv2mxbaqV M3FXsD36+VA5zv+D/m4H9QQcJ5RJV36vSRmv0idFo9JQMF7a67NfH4lDYlWqyZJqQmbFSN 5NXbcA75WIVbSXd3zYbGaY51SiGukxQr8HRERYeI06HCjjteHEktSxPCZRRDQwaGPJEdAE MzmItp7FRvmc1F7T1EJf5d7nlBximJT9pRm/yt1OiQNCIDyn4FfsAq3AdTqoGA== 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 4VQPh82PSHz18jB; Thu, 25 Apr 2024 18:36:24 +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 43PIaOD4032759; Thu, 25 Apr 2024 18:36:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43PIaO1i032756; Thu, 25 Apr 2024 18:36:24 GMT (envelope-from git) Date: Thu, 25 Apr 2024 18:36:24 GMT Message-Id: <202404251836.43PIaO1i032756@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: 1ed44fcc44b2 - main - tftpd: Use `size_t` where appropriate. 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: 1ed44fcc44b2c04db330663589541608135402f4 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=1ed44fcc44b2c04db330663589541608135402f4 commit 1ed44fcc44b2c04db330663589541608135402f4 Author: Dag-Erling Smørgrav AuthorDate: 2024-04-25 18:35:15 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-04-25 18:36:12 +0000 tftpd: Use `size_t` where appropriate. * Limit the use of `ssize_t` to only where it's needed. * Correct one case of `int` being used for a length. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D44954 --- libexec/tftpd/tests/functional.c | 52 ++++++++++++++++++++++++---------------- libexec/tftpd/tftp-utils.c | 4 ++-- libexec/tftpd/tftp-utils.h | 2 +- libexec/tftpd/tftpd.c | 16 ++++++------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/libexec/tftpd/tests/functional.c b/libexec/tftpd/tests/functional.c index 0bdbcfe559ed..bf7b5c77c898 100644 --- a/libexec/tftpd/tests/functional.c +++ b/libexec/tftpd/tests/functional.c @@ -51,8 +51,8 @@ static bool s_flag = false; /* Pass -s to tftpd */ static bool w_flag = false; /* Pass -w to tftpd */ /* Helper functions*/ -static void require_bufeq(const char *expected, ssize_t expected_len, - const char *actual, ssize_t len); +static void require_bufeq(const char *expected, size_t expected_len, + const char *actual, size_t len); /* * Receive a response from tftpd @@ -68,7 +68,7 @@ static void require_bufeq(const char *expected, ssize_t expected_len, (struct sockaddr*)&from, &fromlen); \ ATF_REQUIRE(r > 0); \ require_bufeq((hdr), sizeof(hdr), buffer, \ - MIN(r, (ssize_t)sizeof(hdr))); \ + MIN((size_t)r, sizeof(hdr))); \ require_bufeq((const char*) (contents), (contents_len), \ &buffer[sizeof(hdr)], r - sizeof(hdr)); \ if (protocol == PF_INET) { \ @@ -117,12 +117,13 @@ recv_data(uint16_t blocknum, const char* contents, size_t contents_len) * @param cmd Command to send, as a char array */ static void -send_bytes(const void* cmd, ssize_t len) +send_bytes(const void *cmd, size_t len) { ssize_t r; r = sendto(s, cmd, len, 0, (struct sockaddr*)(&addr), addr.ss_len); - ATF_REQUIRE_EQ(r, len); + ATF_REQUIRE(r >= 0); + ATF_REQUIRE_EQ(len, (size_t)r); } static void @@ -261,16 +262,16 @@ cleanup(void) /* Assert that two binary buffers are identical */ static void -require_bufeq(const char *expected, ssize_t expected_len, const char *actual, - ssize_t len) +require_bufeq(const char *expected, size_t expected_len, const char *actual, + size_t len) { - ssize_t i; + size_t i; ATF_REQUIRE_EQ_MSG(expected_len, len, - "Expected %zd bytes but got %zd", expected_len, len); + "Expected %zu bytes but got %zu", expected_len, len); for (i = 0; i < len; i++) { ATF_REQUIRE_EQ_MSG(actual[i], expected[i], - "Expected %#hhx at position %zd; got %hhx instead", + "Expected %#hhx at position %zu; got %hhx instead", expected[i], i, actual[i]); } } @@ -391,8 +392,8 @@ write_all(int fd, const void *buf, size_t nbytes) while (nbytes > 0) { r = write(fd, buf, nbytes); ATF_REQUIRE(r > 0); - nbytes -= r; - buf = (const char*)buf + r; + nbytes -= (size_t)r; + buf = (const char*)buf + (size_t)r; } } @@ -804,8 +805,9 @@ TFTPD_TC_DEFINE(w_flag,, w_flag = 1;) fd = open("small.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq(contents, contents_len, buffer, r); + require_bufeq(contents, contents_len, buffer, (size_t)r); } /* @@ -841,8 +843,9 @@ TFTPD_TC_DEFINE(wrq_dropped_ack,) fd = open("medium.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq((const char*)contents, 768, buffer, r); + require_bufeq((const char*)contents, 768, buffer, (size_t)r); } /* @@ -874,8 +877,9 @@ TFTPD_TC_DEFINE(wrq_dropped_data,) fd = open("small.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq(contents, contents_len, buffer, r); + require_bufeq(contents, contents_len, buffer, (size_t)r); } /* @@ -908,8 +912,9 @@ TFTPD_TC_DEFINE(wrq_duped_data,) fd = open("medium.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq((const char*)contents, 768, buffer, r); + require_bufeq((const char*)contents, 768, buffer, (size_t)r); } /* @@ -972,8 +977,9 @@ TFTPD_TC_DEFINE(wrq_medium,) fd = open("medium.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq((const char*)contents, 768, buffer, r); + require_bufeq((const char*)contents, 768, buffer, (size_t)r); } /* @@ -1004,8 +1010,9 @@ TFTPD_TC_DEFINE(wrq_medium_window,) fd = open("medium.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq((const char*)contents, 768, buffer, r); + require_bufeq((const char*)contents, 768, buffer, (size_t)r); } /* @@ -1037,8 +1044,9 @@ TFTPD_TC_DEFINE(wrq_netascii,) fd = open("unix.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq(expected, sizeof(expected), buffer, r); + require_bufeq(expected, sizeof(expected), buffer, (size_t)r); } /* @@ -1075,8 +1083,9 @@ TFTPD_TC_DEFINE(wrq_small,) fd = open("small.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq(contents, contents_len, buffer, r); + require_bufeq(contents, contents_len, buffer, (size_t)r); } /* @@ -1162,8 +1171,9 @@ TFTPD_TC_DEFINE(wrq_window_rfc7440,) fd = open("rfc7440.txt", O_RDONLY); ATF_REQUIRE(fd >= 0); r = read(fd, buffer, sizeof(buffer)); + ATF_REQUIRE(r > 0); close(fd); - require_bufeq(contents, sizeof(contents), buffer, r); + require_bufeq(contents, sizeof(contents), buffer, (size_t)r); } diff --git a/libexec/tftpd/tftp-utils.c b/libexec/tftpd/tftp-utils.c index 9754c3238d50..b309a94f7653 100644 --- a/libexec/tftpd/tftp-utils.c +++ b/libexec/tftpd/tftp-utils.c @@ -104,8 +104,8 @@ unmappedaddr(struct sockaddr_in6 *sin6) } /* Get a field from a \0 separated string */ -ssize_t -get_field(int peer, char *buffer, ssize_t size) +size_t +get_field(int peer, char *buffer, size_t size) { char *cp = buffer; diff --git a/libexec/tftpd/tftp-utils.h b/libexec/tftpd/tftp-utils.h index 3fecf1fc8696..763b3b493c7e 100644 --- a/libexec/tftpd/tftp-utils.h +++ b/libexec/tftpd/tftp-utils.h @@ -63,7 +63,7 @@ extern int acting_as_client; /* */ void unmappedaddr(struct sockaddr_in6 *sin6); -ssize_t get_field(int peer, char *buffer, ssize_t size); +size_t get_field(int peer, char *buffer, size_t size); /* * Packet types diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 9b56029797ec..45e7344c86ed 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -68,8 +68,8 @@ #include #endif -static void tftp_wrq(int peer, char *, ssize_t); -static void tftp_rrq(int peer, char *, ssize_t); +static void tftp_wrq(int peer, char *, size_t); +static void tftp_rrq(int peer, char *, size_t); /* * Null-terminated directory prefix list for absolute pathname requests and @@ -81,7 +81,7 @@ static void tftp_rrq(int peer, char *, ssize_t); #define MAXDIRS 20 static struct dirlist { const char *name; - int len; + size_t len; } dirs[MAXDIRS+1]; static int suppress_naks; static int logging; @@ -392,7 +392,7 @@ main(int argc, char *argv[]) tp->th_opcode = ntohs(tp->th_opcode); if (tp->th_opcode == RRQ) { if (allow_ro) - tftp_rrq(peer, tp->th_stuff, n - 1); + tftp_rrq(peer, tp->th_stuff, (size_t)n - 1); else { tftp_log(LOG_WARNING, "%s read access denied", peername); @@ -400,7 +400,7 @@ main(int argc, char *argv[]) } } else if (tp->th_opcode == WRQ) { if (allow_wo) - tftp_wrq(peer, tp->th_stuff, n - 1); + tftp_wrq(peer, tp->th_stuff, (size_t)n - 1); else { tftp_log(LOG_WARNING, "%s write access denied", peername); @@ -443,7 +443,7 @@ reduce_path(char *fn) } static char * -parse_header(int peer, char *recvbuffer, ssize_t size, +parse_header(int peer, char *recvbuffer, size_t size, char **filename, char **mode) { char *cp; @@ -489,7 +489,7 @@ parse_header(int peer, char *recvbuffer, ssize_t size, * WRQ - receive a file from the client */ void -tftp_wrq(int peer, char *recvbuffer, ssize_t size) +tftp_wrq(int peer, char *recvbuffer, size_t size) { char *cp; int has_options = 0, ecode; @@ -534,7 +534,7 @@ tftp_wrq(int peer, char *recvbuffer, ssize_t size) * RRQ - send a file to the client */ void -tftp_rrq(int peer, char *recvbuffer, ssize_t size) +tftp_rrq(int peer, char *recvbuffer, size_t size) { char *cp; int has_options = 0, ecode;