Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Feb 2002 01:35:34 -0500 (EST)
From:      Mikhail Teterin <mi@aldan.algebra.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/34601: bc(1)'s multi-line file parsing problem
Message-ID:  <200202040635.g146ZY907522@aldan.algebra.com>

next in thread | raw e-mail | index | archive | help

>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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200202040635.g146ZY907522>