From nobody Tue Feb 15 13:43:35 2022 X-Original-To: dev-commits-src-main@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 CCB5719B8ADB; Tue, 15 Feb 2022 13:43:35 +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 4Jyj3W5PSTz4vJW; Tue, 15 Feb 2022 13:43:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644932615; 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=ovIJezU69bPk0hW2E4JAnIHAHdp9dnqdrQZOC1jwsNs=; b=FRvZ2TNeKP4X7ZhiD7dGFN9I3S4IZwkjcPv2X5ud9FgpcI6apxiSZrnVPEp6AECIcpCoi0 bN5gfJ5HLXBIpHeBtRshVz9O403b4O6KcZRJriRoOoKHrkCAc04+Kiyr1FCYhiG2PBQLET uO2Xj9h1M7x1frF+NsK2C2xq5KHh4A8lCjK2L5VKpXrrnzxroGHOejQiW56UaPJ1hLdk3n UUO/Gp39/JF22eT0ez79VxU/WXqyl3ZoY9lPeFWcjXoz1llnLojjq9Z55B+sVz8p0c7fMo SyJ6yazytg1hZpyOb7jp+LpKBvYoOHnAeA2zrJaO/qf2cvYAsNmYno7ZCROWxw== 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 8EA3F233D7; Tue, 15 Feb 2022 13:43:35 +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 21FDhZeT082476; Tue, 15 Feb 2022 13:43:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21FDhZ9r082475; Tue, 15 Feb 2022 13:43:35 GMT (envelope-from git) Date: Tue, 15 Feb 2022 13:43:35 GMT Message-Id: <202202151343.21FDhZ9r082475@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 82b611ed18e6 - main - elfctl: fix operations with multiple features on multiple files List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 82b611ed18e6bfaeadf152ef9216230548c25a8a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644932615; 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=ovIJezU69bPk0hW2E4JAnIHAHdp9dnqdrQZOC1jwsNs=; b=AWxQ6z2wjPODn81d4VYawx45yMd8qvHRba/RTmY0Zk1LaqJFroXOqgTBWy6Tm4o4avfSQW P9dXuSEcjj32x5IteZ9FvoAzmoPpFpxyaLnV7JOB6kmjVkg08g/Il8YyZMtR9ebRLHjxQr qS4um+fFM8yavSAyjj3g3IPzR4rpGDa5B32SrPOeofYJvhttbkyAzQR9NbxcdPY2xGpiBC d11fiQ/2ZRENQzdIbkLv+xbhnLS7CgB/ac3EUxwpWtOBQtIHOIdoODGYr662OmyWXhSZuM EbL+juxUL/tfdbdY0c+LniP7jSC6S3FZDvfRaaIgVDAS0ONpJ7KlTY47h5nUjA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644932615; a=rsa-sha256; cv=none; b=Ea5RluAvfDJ2gIilQFPk2wXBitaEmvgTXPnYgEwayL/oyIxPERB4OhgHr2ifgQGixN8u8x 6oJfkmyPNYYjlQWoN8dUojB7T+4Fi8fmFsIyHjaJ78tsv/JULGEzmSM6YYHuNXeCUP3tJ4 qBIU4jKrEpFrNkUdHbN2TV421tS8ZZCj5HKGUMc1rcJf/A65jt7Ewnmp1BA7xZl/wSkudh ltVEcgkG8jxrxbczoMxx7yUUEgY6RZZWz7P/48tsvmpn+TsN4vX5xuQfg/QWBpQ9ZyGz1P oxyL3yU6LA+o6YHej96x8rWeNmIOE+9LanWdEVNkbg0lqeScUzY9T9K+4SJhgg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=82b611ed18e6bfaeadf152ef9216230548c25a8a commit 82b611ed18e6bfaeadf152ef9216230548c25a8a Author: Ed Maste AuthorDate: 2022-02-15 03:44:01 +0000 Commit: Ed Maste CommitDate: 2022-02-15 13:42:17 +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 --- 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); }