From nobody Fri Feb 18 01:51:00 2022 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 108BA19C128A; Fri, 18 Feb 2022 01:51: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 4K0F5w5KJyz4b66; Fri, 18 Feb 2022 01:51:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645149060; 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=ZqJnNjqbg4jl4c2uUyw4e28jixnCz6rPfoFzy12IoYs=; b=XX/c/+ea+430teDWjR5U8XQrl8Nio52z5f+Boa3A6F4rzvr0IyB3SxZrsn4WGgRii1x/eD VNlzAsxga2Nq1laQnOFlBQdiYD5aTmYwzZGdkKcAtmBOO8qFf+L/2sOyIb3bDiItE25T+F 8lH2T5cGYvngfZVVyxbPlw87MO3KMGSVWepAAjXafHd1fXnLSPq+3Azsmg6k/j9T2B+ZG6 TyALIva51S9QhednpUQkyVl0IR1hrhbD59cB1vfaYf5dMSslZhjottBISoU67WNgnVhQgB wfAP8VEyhYm5iRqsbUEhz2531glNBjhaNS09jjtLc1o9vu8vfmsuH+3Ozy+x2w== 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 726F714EEC; Fri, 18 Feb 2022 01:51:00 +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 21I1p0iv026004; Fri, 18 Feb 2022 01:51:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21I1p0wV026003; Fri, 18 Feb 2022 01:51:00 GMT (envelope-from git) Date: Fri, 18 Feb 2022 01:51:00 GMT Message-Id: <202202180151.21I1p0wV026003@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: cac751fb5f09 - stable/13 - elfctl: fix operations with multiple features on multiple files 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cac751fb5f099568d2ed13779ca7b7c22221a605 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645149060; 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=ZqJnNjqbg4jl4c2uUyw4e28jixnCz6rPfoFzy12IoYs=; b=KAVcg8ZHTl9DfhEd0RAvgjbu9D/lcO2+uDzpAwlbrg4NK9UOQdv8dovxvDAG3g9pLHKiGK njvLmbm2ZL7FrZEXqYsTm6Dl5LnPEW7q9CGZIL4xsFSUyNcTHYDUt1e8Vcvt0hZtNcNHZD ujy156xV+GvSlzOuZfMjxFT95r489BxkP6G3rtizsQsnVmDMom3FZBoSd9mYKnkgIHy+YN y6w6Q9puNrQGqqZSWWccjD50LAAj45NS851kaxy075r3V3eRxFEHT+dGWSO1QVd6W82sbU W2NZ3/GQFOaP/qtVEa69ZVTEiqpgSP2vKoLXWhtu4kqLA5tVD6uzsK7GWZC6OA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645149060; a=rsa-sha256; cv=none; b=X1YRk9jUvMcimvJQJxvRIJSiiGIUwXAUvxuQKf2Hwn9lIGAu+zJfZNB2bgwK1ef/bnyhmr LKvuYULJ5lmwNhF3dkmp0eV8aNbQf8hLSarrqqJrGZqCzHXoXYkic5TyFFlqyEztrE/Jdz 6Xx6EoaC+Sfr6ILT1dMSxFBok1PwQe2IJN7RfdZ9LRbVrpb8qVdn0Yd2JNh0dC2dCeSyCF LlQjUyvCYcChWKgbsdiIhDNpwWydJzZocMqKizVPkE6TPy7RcTCEnmDLr2fXA8NKC2hTZf r7vRnfnurSsA5jyV45QM5sGYIq00div+evA0SaM1PwM/xVjRe0Kbw7HQ4TDxCA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=cac751fb5f099568d2ed13779ca7b7c22221a605 commit cac751fb5f099568d2ed13779ca7b7c22221a605 Author: Ed Maste AuthorDate: 2022-02-15 03:44:01 +0000 Commit: Ed Maste CommitDate: 2022-02-18 00:31:57 +0000 elfctl: fix operations with multiple features on multiple files Previously an invocation like elfctl -e +feature1,feature2 file1 file2 would set both feature flags in file 1 but only feature1 in file2 (due to the string being modified by strsep()). Reported by: jrm Tested by: jrm MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34283 (cherry picked from commit 82b611ed18e6bfaeadf152ef9216230548c25a8a) --- usr.bin/elfctl/elfctl.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c index 993349d4ec4c..7cd851f20170 100644 --- a/usr.bin/elfctl/elfctl.c +++ b/usr.bin/elfctl/elfctl.c @@ -51,7 +51,7 @@ __FBSDID("$FreeBSD$"); -static bool convert_to_feature_val(char *, uint32_t *); +static bool convert_to_feature_val(const char *, uint32_t *); static bool edit_file_features(Elf *, int, int, char *, bool); static bool get_file_features(Elf *, int, int, uint32_t *, uint64_t *, bool); static void print_features(void); @@ -222,9 +222,9 @@ usage(void) } static bool -convert_to_feature_val(char *feature_str, uint32_t *feature_val) +convert_to_feature_val(const char *feature_str, uint32_t *feature_val) { - char *feature; + char *feature, *feature_tmp; int i, len; uint32_t input; char operation; @@ -236,8 +236,10 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val) if (operation != '+' && operation != '-' && operation != '=') errx(1, "'%c' not an operator - use '+', '-', '='", operation); + if ((feature_tmp = strdup(feature_str)) == NULL) + err(1, "strdup"); len = nitems(featurelist); - while ((feature = strsep(&feature_str, ",")) != NULL) { + while ((feature = strsep(&feature_tmp, ",")) != NULL) { for (i = 0; i < len; ++i) { if (strcmp(featurelist[i].alias, feature) == 0) { input |= featurelist[i].value; @@ -267,13 +269,16 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val) errno = ERANGE; if (errno != 0) { warn("%s invalid", feature); + free(feature_tmp); return (false); } input |= val; } else { warnx("%s is not a valid feature", feature); - if (!iflag) + if (!iflag) { + free(feature_tmp); return (false); + } } } } @@ -285,6 +290,7 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val) } else if (operation == '-') { *feature_val &= ~input; } + free(feature_tmp); return (true); }