From patchwork Wed Dec 14 02:31:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13072710 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AEADC4332F for ; Wed, 14 Dec 2022 02:31:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229699AbiLNCbg (ORCPT ); Tue, 13 Dec 2022 21:31:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbiLNCbf (ORCPT ); Tue, 13 Dec 2022 21:31:35 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C563D1E3F7 for ; Tue, 13 Dec 2022 18:31:33 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 8655FE66 for ; Wed, 14 Dec 2022 03:31:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1670985091; bh=V5ybB/D+/KqQiBMNlJVXsEIMIycAgfneIt9WRKhi3sg=; h=Date:From:To:Subject:From; b=lDABUUL8AbY9VTyQ0xvI5tiC8csoZh+DljiqVlGYbw/QvRLBsgUP+0kmo6mpeK/8F cKEy2jfEedpvmzYpVDyi2D2fX2FLsgK1aUNiTvnEqDzQFYdKrAjON/Ek2SKrUajYdc MYvlSYICFDGIP2KsFEKlxNNLSpD50Hc/owVdghtdnVEowFBapc2LKq2l/Q3LkoeHYV U0udHitEPA8q3/mnfYO3yg0u+BbPB9EZTRtNyew7MsOZvVtsXracHRo8hVOceYtbXW 4jZBxlr0aQ7c9Kpo73X4FIYkHJ1Hwl3DOVpsfb4Im+5CWOVhJVGCe4dkaxztjFVeTI 1fxNaT+RdLc2A== Date: Wed, 14 Dec 2022 03:31:30 +0100 From: =?utf-8?b?0L3QsNCx?= To: dash@vger.kernel.org Subject: [PATCH] options: don't error when unsetting OPTIND Message-ID: <20221214023130.u7pn4ca6ma4kuxot@tarta.nabijaczleweli.xyz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org unset OPTIND ends up calling getoptsreset("") which errors out with sh: 1: unset: Illegal number: or even sh: 1: unset: Illegal number: leweli/bin:/usr/l�� Pass the current flags to struct var->func, set the getopts optind to 1 and continue with allowing the unset. We still forbid OPTIND=, OPTIND=-1, OPTIND=abc, &c. Fixes: https://bugs.debian.org/985478 --- src/exec.c | 2 +- src/exec.h | 2 +- src/mail.c | 2 +- src/mail.h | 2 +- src/options.c | 5 ++--- src/options.h | 2 +- src/var.c | 4 ++-- src/var.h | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/exec.c b/src/exec.c index 87354d4..68fa8ab 100644 --- a/src/exec.c +++ b/src/exec.c @@ -565,7 +565,7 @@ hashcd(void) */ void -changepath(const char *newval) +changepath(const char *newval, int unused) { const char *new; int idx; diff --git a/src/exec.h b/src/exec.h index 423b07e..0f74be4 100644 --- a/src/exec.h +++ b/src/exec.h @@ -69,7 +69,7 @@ int hashcmd(int, char **); void find_command(char *, struct cmdentry *, int, const char *); struct builtincmd *find_builtin(const char *); void hashcd(void); -void changepath(const char *); +void changepath(const char *, int); #ifdef notdef void getcmdentry(char *, struct cmdentry *); #endif diff --git a/src/mail.c b/src/mail.c index 8eacb2d..e81d2b4 100644 --- a/src/mail.c +++ b/src/mail.c @@ -109,7 +109,7 @@ chkmail(void) void -changemail(const char *val) +changemail(const char *val, int unused) { changed++; } diff --git a/src/mail.h b/src/mail.h index 3c6b21d..70b54a4 100644 --- a/src/mail.h +++ b/src/mail.h @@ -35,4 +35,4 @@ */ void chkmail(void); -void changemail(const char *); +void changemail(const char *, int); diff --git a/src/options.c b/src/options.c index a46c23b..81f2c4b 100644 --- a/src/options.c +++ b/src/options.c @@ -390,10 +390,9 @@ setcmd(int argc, char **argv) void -getoptsreset(value) - const char *value; +getoptsreset(const char *value, int flags) { - shellparam.optind = number(value) ?: 1; + shellparam.optind = (flags & VUNSET) ? 1 : number(value) ?: 1; shellparam.optoff = -1; } diff --git a/src/options.h b/src/options.h index 975fe33..10bcb88 100644 --- a/src/options.h +++ b/src/options.h @@ -83,4 +83,4 @@ int shiftcmd(int, char **); int setcmd(int, char **); int getoptscmd(int, char **); int nextopt(const char *); -void getoptsreset(const char *); +void getoptsreset(const char *, int); diff --git a/src/var.c b/src/var.c index ef9c2bd..a7d4a92 100644 --- a/src/var.c +++ b/src/var.c @@ -266,7 +266,7 @@ struct var *setvareq(char *s, int flags) goto out; if (vp->func && (flags & VNOFUNC) == 0) - (*vp->func)(strchrnul(s, '=') + 1); + (*vp->func)(strchrnul(s, '=') + 1, flags); if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) ckfree(vp->text); @@ -531,7 +531,7 @@ poplocalvars(void) unsetvar(vp->text); } else { if (vp->func) - (*vp->func)(strchrnul(lvp->text, '=') + 1); + (*vp->func)(strchrnul(lvp->text, '=') + 1, lvp->flags); if ((vp->flags & (VTEXTFIXED|VSTACK)) == 0) ckfree(vp->text); vp->flags = lvp->flags; diff --git a/src/var.h b/src/var.h index aa7575a..4329e22 100644 --- a/src/var.h +++ b/src/var.h @@ -56,7 +56,7 @@ struct var { struct var *next; /* next entry in hash list */ int flags; /* flags are defined above */ const char *text; /* name=value */ - void (*func)(const char *); + void (*func)(const char *, int flags); /* function to be called when */ /* the variable gets set/unset */ };