From owner-freebsd-bugs Thu Jan 18 18:10:19 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 5C93F37B69D for ; Thu, 18 Jan 2001 18:10:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f0J2A1134190; Thu, 18 Jan 2001 18:10:01 -0800 (PST) (envelope-from gnats) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 66A2C37B69B for ; Thu, 18 Jan 2001 18:09:20 -0800 (PST) Received: (from nobody@localhost) by freefall.freebsd.org (8.11.1/8.11.1) id f0J29KO34102; Thu, 18 Jan 2001 18:09:20 -0800 (PST) (envelope-from nobody) Message-Id: <200101190209.f0J29KO34102@freefall.freebsd.org> Date: Thu, 18 Jan 2001 18:09:20 -0800 (PST) From: hunt@iprg.nokia.com To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: bin/24443: Fix for spurious "arith: syntax error: " problem in sh Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 24443 >Category: bin >Synopsis: Fix for spurious "arith: syntax error: " problem in sh >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jan 18 18:10:01 PST 2001 >Closed-Date: >Last-Modified: >Originator: Peter Hunt >Release: 3.4-RELEASE >Organization: Nokia IP Inc. >Environment: FreeBSD rebempire.iprg.nokia.com 3.4-RELEASE FreeBSD 3.4-RELEASE #0: Mon Mar 13 06:51:40 PST 2000 root@rebempire.iprg.nokia.com:/usr/src/sys/compile/IPRG i386 >Description: The symptom of the problem is a spurious arithmetic expression syntax error when executing a shell script line of the form: VARIABLE=$((1000 * 1024)) The error that appears is of the form: scriptname: arith: syntax error: "o" The problem is caused by an error in expari() in expand.c in sh. >How-To-Repeat: This problem is extremely hard to reproduce, as it depends on the specifics of previous arithmetic expressions in the shell script. I could reproduce it all the time with one very large script, which I can't submit, but wasn't able to do so with smaller scripts. >Fix: The existing code does the following: CHECKSTRSPACE(12 - 2, expdest); USTPUTC('\0', expdest); start = stackblock(); p = expdest; while (*p != CTLARI && p >= start) --p; The problem is that expdest points to the next unused location on the stack, so the character at that location is just garbage left over from a previous expression. p is set to that location, so the first iteration of the while loop will test that garbage character for CTLARI. If it happens to be CTLARI, the code will attempt to evaluate the characters above the top of the stack as an arithmetic expression, and (likely) fail. This is what was happening in the case I saw. The solution I propose is to change the while loop to a do loop: CHECKSTRSPACE(12 - 2, expdest); USTPUTC('\0', expdest); start = stackblock(); p = expdest; do { --p; } while (*p != CTLARI && p >= start); ... so that p gets decremented before the first test. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message