From owner-freebsd-bugs Sun Feb 3 22:40: 8 2002 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 C6E1737B419 for ; Sun, 3 Feb 2002 22:40:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g146e1b58872; Sun, 3 Feb 2002 22:40:01 -0800 (PST) (envelope-from gnats) Received: from aldan.algebra.com (aldan.algebra.com [216.254.65.224]) by hub.freebsd.org (Postfix) with ESMTP id 77B0F37B405 for ; Sun, 3 Feb 2002 22:36:05 -0800 (PST) Received: (from mi@localhost) by aldan.algebra.com (8.11.6/8.11.5) id g146ZY907522; Mon, 4 Feb 2002 01:35:34 -0500 (EST) (envelope-from mi) Message-Id: <200202040635.g146ZY907522@aldan.algebra.com> Date: Mon, 4 Feb 2002 01:35:34 -0500 (EST) From: Mikhail Teterin Reply-To: Mikhail Teterin To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/34601: bc(1)'s multi-line file parsing problem Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 34601 >Category: bin >Synopsis: bc(1)'s multi-line file parsing problem >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Feb 03 22:40:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Mikhail Teterin >Release: FreeBSD 5.0-CURRENT i386 >Organization: Virtual Estates, Inc. >Environment: System: FreeBSD aldan.algebra.com 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Thu Jan 3 21:38:15 EST 2002 mi@aldan.algebra.com:/ccd/obj/ccd/src/sys/DEBUG i386 >Description: Depending on the weather (or compilation flags) bc's parsing of multi-line files involving function definitions may break. This is best manifested, when bc is parsing its own libmath -- triggered by the ``-l'' flag (use_math). The /usr/src/contrib/bc/bc/libmath.h contains the code of bc's math-library, which is parsed if the -l flag is given. The code contains several functions, which are, evidently, defined using multiple lines -- between the opening ``['' and the closing ``]''. The code in load_code is not prepared for this. When it sees the closing ``]'' at line 280 it assumes, that save_adr contains the address saved when it saw the opening ``[''. However, save_adr is an atomic variable, which is not initialized if the opening ``['' occured in one of the previous lines. Depending on save_adr's value bc will or will not crash shortly after. >How-To-Repeat: I compile everything with CFLAGS= -O -pipe -march=i686 ${PROG:C/.+/-fomit-frame-pointer/} which means that bc, whose Makefile declares PROG, was built with CFLAGS=-O -pipe -march=i686 -fomit-frame-pointer this was enough for me to stumble upon this on both 5-CURRENT and 4.4-STABLE machines. echo 20 | bc -l However, I was able to reproduce it with simple -g. It works properly on freefall... >Fix: Either the save_adr should be made static or the whole libmath needs to be parsed as one big string. For the former, the patch would be simple. Not sure about about the latter or something third... RCS file: /home/ncvs/src/contrib/bc/bc/load.c,v retrieving revision 1.1.1.2 diff -U2 -r1.1.1.2 load.c --- load.c 26 Feb 2001 07:12:53 -0000 1.1.1.2 +++ load.c 4 Feb 2002 06:31:12 -0000 @@ -157,5 +157,5 @@ long vaf_name; /* variable, array or function number. */ long func; - program_counter save_adr; + static program_counter save_adr; /* Initialize. */ >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message