From owner-dev-commits-src-all@freebsd.org Sat Jan 30 22:59:08 2021 Return-Path: Delivered-To: dev-commits-src-all@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 D69824FB9F5; Sat, 30 Jan 2021 22:59:08 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from hz.grosbein.net (hz.grosbein.net [IPv6:2a01:4f8:c2c:26d8::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "hz.grosbein.net", Issuer "hz.grosbein.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DSqQN4Qw0z3PWr; Sat, 30 Jan 2021 22:59:08 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from eg.sd.rdtc.ru (eg.sd.rdtc.ru [IPv6:2a03:3100:c:13:0:0:0:5]) by hz.grosbein.net (8.15.2/8.15.2) with ESMTPS id 10UMwruC077371 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 30 Jan 2021 22:58:55 GMT (envelope-from eugen@grosbein.net) X-Envelope-From: eugen@grosbein.net X-Envelope-To: jilles@stack.nl Received: from [10.58.0.10] (dadvw [10.58.0.10]) by eg.sd.rdtc.ru (8.16.1/8.16.1) with ESMTPS id 10UMwjdm097125 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 31 Jan 2021 05:58:45 +0700 (+07) (envelope-from eugen@grosbein.net) Subject: Re: git: 3708b615c354 - stable/12 - sh: Allow more scripts without #! To: Jilles Tjoelker References: <202101301511.10UFBjcd033018@gitrepo.freebsd.org> <5cee1fe4-8aa8-0ad7-55ab-125bfbcb7c7f@grosbein.net> <20210130222616.GA4539@stack.nl> Cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Message-ID: Date: Sun, 31 Jan 2021 05:58:39 +0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20210130222616.GA4539@stack.nl> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,LOCAL_FROM, NICE_REPLY_A,SPF_HELO_NONE,T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.2 X-Spam-Report: * -2.3 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record * 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) * 2.6 LOCAL_FROM From my domains * -0.0 NICE_REPLY_A Looks like a legit reply (A) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hz.grosbein.net X-Rspamd-Queue-Id: 4DSqQN4Qw0z3PWr X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jan 2021 22:59:08 -0000 31.01.2021 5:26, Jilles Tjoelker wrote: >>> +static bool >>> +isbinary(const char *data, size_t len) >>> +{ >>> + const char *nul, *p; >>> + bool hasletter; >>> + >>> + nul = memchr(data, '\0', len); >>> + if (nul == NULL) >>> + return false; >>> + /* >>> + * POSIX says we shall allow execution if the initial part intended >>> + * to be parsed by the shell consists of characters and does not >>> + * contain the NUL character. This allows concatenating a shell >>> + * script (ending with exec or exit) and a binary payload. >>> + * >>> + * In order to reject common binary files such as PNG images, check >>> + * that there is a lowercase letter or expansion before the last >>> + * newline before the NUL character, in addition to the check for >>> + * the newline character suggested by POSIX. >>> + */ >>> + hasletter = false; >>> + for (p = data; *p != '\0'; p++) { >>> + if ((*p >= 'a' && *p <= 'z') || *p == '$' || *p == '`') >>> + hasletter = true; >>> + if (hasletter && *p == '\n') >>> + return false; >>> + } >>> + return true; >>> +} > >> Before last newline or before first newline? > > Before the last newline, according to both comment and code. Sorry, I don't get it. The "for" loop starts from the beginning, and returns false (NOT binary, text file) after lowercase letter and first newline, not last.