From owner-dev-commits-src-main@freebsd.org Sun Dec 27 21:32:36 2020 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BC7364C7A5D; Sun, 27 Dec 2020 21:32:36 +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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D3v6D4wTRz3j26; Sun, 27 Dec 2020 21:32:36 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9C2C2631A; Sun, 27 Dec 2020 21:32:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BRLWaoV010545; Sun, 27 Dec 2020 21:32:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BRLWalR010544; Sun, 27 Dec 2020 21:32:36 GMT (envelope-from git) Date: Sun, 27 Dec 2020 21:32:36 GMT Message-Id: <202012272132.0BRLWalR010544@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Stefan Eßer Subject: git: 50fcb4ee771c - main - Replace sscanf() by strtoul() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 50fcb4ee771cabbae99bb3150b26484f3e573fab Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "Commit messages for the main branch of the src repository." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Dec 2020 21:32:36 -0000 The branch main has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=50fcb4ee771cabbae99bb3150b26484f3e573fab commit 50fcb4ee771cabbae99bb3150b26484f3e573fab Author: Stefan Eßer AuthorDate: 2020-12-26 21:21:49 +0000 Commit: Stefan Eßer CommitDate: 2020-12-27 21:32:22 +0000 Replace sscanf() by strtoul() This change has been motivated by a mail from bde sent in 2015 in which he mentioned inappropriate use of sscanf() in 3 programs in /bin. This change removes the potential mismatch of the types of the return values and the variable width specified in the scan pattern. While there was no issue with the patterns and types used, the new code is simpler and more efficient. --- bin/stty/gfmt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/stty/gfmt.c b/bin/stty/gfmt.c index 055edf880bd6..12ed2a2d3500 100644 --- a/bin/stty/gfmt.c +++ b/bin/stty/gfmt.c @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include "stty.h" @@ -85,7 +86,7 @@ gread(struct termios *tp, char *s) if (!(ep = strchr(p, '='))) gerr(p); *ep++ = '\0'; - (void)sscanf(ep, "%lx", (u_long *)&tmp); + tmp = strtoul(ep, NULL, 0x10); #define CHK(s) (*p == s[0] && !strcmp(p, s)) if (CHK("cflag")) { @@ -97,7 +98,7 @@ gread(struct termios *tp, char *s) continue; } if (CHK("ispeed")) { - (void)sscanf(ep, "%ld", &tmp); + tmp = strtoul(ep, NULL, 10); tp->c_ispeed = tmp; continue; } @@ -110,14 +111,14 @@ gread(struct termios *tp, char *s) continue; } if (CHK("ospeed")) { - (void)sscanf(ep, "%ld", &tmp); + tmp = strtoul(ep, NULL, 10); tp->c_ospeed = tmp; continue; } for (cp = cchars1; cp->name != NULL; ++cp) if (CHK(cp->name)) { if (cp->sub == VMIN || cp->sub == VTIME) - (void)sscanf(ep, "%ld", &tmp); + tmp = strtoul(ep, NULL, 10); tp->c_cc[cp->sub] = tmp; break; }