mainAutoconf - Support: sr #110654, On AT&T UnixPC (3b1) autoconf...

 
 

sr #110654: On AT&T UnixPC (3b1) autoconf script fails to properly replace $LINENO variable with line number

Submitter:  Alain Knaff <alainknaff>
Submitted:  Sun 15 May 2022 11:07:40 AM UTC
   
 
Priority:  * 5 - Unprioritized Severity:  3 - Normal
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 16 May 2022 05:19:00 AM UTC, comment #1: 

Thanks for the bug report. Although the 3b1 is a museum piece the Autoconf manual says other old sed implementations have a similar bug and the fix is trivial, so I installed the attached.

(file #53209)

Paul Eggert <eggert>
Group administrator
Sun 15 May 2022 11:07:40 AM UTC, original submission:  

Hi,

Autoconfigure scripts generated by GNU autoconf pass themselves through a pair sed script to substitute $LINENO variable with the actual line number if the shell itself does not support a $LINENO variable.

The first sed script adds a line with just the line number after each line containing $LINENO.
The second script then substitutes $LINENO with the contents of next line (the line number placed by first script)

This second script fails on AT&T UnixPC (3b1) and leaves some of the line numbers in the file on their line on their own.


This is due to a different behavior of sed's "t" command.
The "t" command branches to the given label if there has been a successful s/// substitution since the last t command.
On most other platforms, "t" only considers substitutions within current "line". However AT&T UnixPC's sed also considers substitutions on previous lines.

This breaks the second script if there are 2 lines with LINENO variable that have exactly one intervening other line between them.

Example:
abc $LINENO
def
fgh $LINENO

This is transformed by the first sed script into
abc $LINENO
1
def
fgh $LINENO
3

The second script first processes the first 2 lines into "abc 1"
However, the removal of the "1" from its own line (s/-\n.*//) is counted as a successful substitution, and is remembered (by UnixPC's sed) for the next line def (other sed implementations would clear this on passing to next line). As the sed script now thinks that def contains a $LINENO variable, it gobbles up the next line "fgh $LINENO" using N command, substitutes $LINENO with following line (i.e. with nothing, as it hasn't read the 3 into pattern space yet => eventually, it moves on to the next line (the unprocessed 3), and leaves the line number as is in the output, on a line by its own, where this number ends up getting executed as a command, which crashes the script.

Fix: this can be addressed by putting an empty branch + label at the end of the second sed script (t end \n :end):

...
    sed '
      s/[$]LINENO.*/&-/
      t lineno
      b
      :lineno
      N
      :loop
      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
      t loop
      s/-\n.*//
      t end
      :end
    ' >$as_me.lineno &&
...

in /usr/share/autoconf/m4sugar/m4sh.m4

N.B. For testing, an AT&T UnixPC emulator can be found at https://github.com/philpem/freebee

Alain Knaff <alainknaff>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #53209:  0001-Work-around-AT-T-3b1-bug.patch added by eggert (819B - text/x-patch - Fix for bug.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by eggert (Updated the item)
  • -email is unavailable- added by alainknaff (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-05-16 eggert Attached File- Added 0001-Work-around-AT-T-3b1-bug.patch, #53209
        StatusNone Done
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code