bugGNU roff - Bugs: bug #66009, [troff] accepts `|` as operand...

 
 

bug #66009: [troff] accepts `|` as operand delimiter, but should not

Submitter:  G. Branden Robinson <gbranden>
Submitted:  Sat 20 Jul 2024 09:10:05 PM UTC
   
 
Category:  Core Severity:  3 - Normal
Item Group:  Warning/Suspicious behaviour Status:  Postponed
Privacy:  Public Assigned to:  gbranden
Open/Closed:  Open Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Tue 28 Jan 2025 08:38:39 AM UTC, comment #4: 


commit 39c1176bfa9ba84d519b015b1453f316e013d1de
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Mon Jan 27 18:52:39 2025 -0600

    [troff]: Fix Savannah #66686 (`\w|foo|` blues).

    * src/roff/troff/input.cpp (is_char_usable_as_delimiter): Restore `|`
      character as an invalid delimiter when not in compatibility mode.
      This would regress the fix for Savannah #66481, but...

      (do_overstrike, do_bracket, do_name_test, do_zero_width_output)
      (read_size, do_register, do_width, do_device_extension)
      (read_drawing_command): Throw warning in "delimiter" category and
      explain ambiguity of delimiter instead of emitting error and refusing
      further interpretation of the escape sequence being parsed.  Leave
      behind "#if"ed code for restoration of former stricter behavior in a
      future groff release (which would fix Savannah #66009).

      (is_conditional_expression_true): Stop special-casing an exception for
      `|` that permitted it to be used as a formatted output comparison
      operator.  Savannah #66481 complained only about groff's rejection of
      `|` to delimit the argument to the `\w` (width measurement) escape
      sequence, not in general, and was seen in some man pages.  The usage
      Paul Eggert reported remains accepted, albeit warned about, per
      `do_width()` above.

    * src/roff/groff/tests/check-delimiter-validity.sh: Update test
      expectations.  We now expect `|` to be invalid once again to delimit a
      line-drawing escape sequence.

    Fixes <https://savannah.gnu.org/bugs/?66686>.  Thanks to Dave Kemper for
    the report.  Savannah #66526 is implicated.

    The uses of `\w|whatever|` cited by Eggert appear to be a chunk of
    boilerplate passed around by some man page authors for GNU man pages.
    Eggert's "tz" package doesn't itself use `|` as a delimiter, but I did
    verify their use in gawk, grep, and rcs.

    gawk:
    .if !\n(.g \{\
    .       if !\w|\*(lq| \{\
    .               ds lq ``
    .               if \w'\(lq' .ds lq "\(lq
    .       \}
    .       if !\w|\*(rq| \{\
    .               ds rq ''
    .               if \w'\(rq' .ds rq "\(rq
    .       \}
    .\}

    grep:
    .if !\w|\*(lq| \{\
    .\" groff an-old.tmac does not seem to be in use, so define lq and rq.
    .       ie \n(.g \{\
    .               ds lq \(lq\"
    .               ds rq \(rq\"
    .       \}
    .       el \{\
    .               ds lq ``
    .               ds rq ''
    .       \}
    .\}

    rcs:
    .if !\n(.g \{\
    .       if !\w|\*(lq| \{\
    .               ds lq ``
    .               if \w'\(lq' .ds lq "\(lq
    .       \}
    .       if !\w|\*(rq| \{\
    .               ds rq ''
    .               if \w'\(rq' .ds rq "\(rq
    .       \}
    .\}

    One observes that only grep(1) doesn't feature-gate its use of `\w|foo|`
    behind a test of the `.g` register (groff-compatible formatter) for
    falsity.  It is therefore the only one of these three that would have
    provoked a warning.  (What the foregoing do is reimplement the `lq` and
    `rq` quotation strings, an extension from 4BSD (1980)--my guess is to
    compensate for System V-based troffs missing them).

    The rcs man pages otherwise use `\w` pretty extensively (which can be
    its own portability worry), but in every other case with the unambiguous
    `'` delimiter.

commit 1eed3cceaaa38e095e2b265cda846842853525e4
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Tue Jan 28 00:57:03 2025 -0600

    [doc,man]: Report new delimiter warning scenario.


G. Branden Robinson <gbranden>
Group administrator
Wed 04 Dec 2024 09:35:10 AM UTC, comment #3: 

When is a delimiter not a delimiter?

When it's `|`, apparently.

See bug #66526.

...which is arguably the same issue as I identified in comment #0, but explored in a different way.

In that bug, I'll deal with special-casing `|` at the start of a conditional expression.  This one is for the language reform.

G. Branden Robinson <gbranden>
Group administrator
Sat 30 Nov 2024 09:09:03 AM UTC, comment #2: 


commit d052cb31d9982ef2ad1d776d828bd4370ce5e43e
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Mon Nov 25 17:13:56 2024 -0600

    [troff]: Fix Savannah #66481 and unfix #66099.

    * src/roff/troff/input.cpp (is_char_usable_as_delimiter): Revert fix for
      bug #66009.  Unfortunately, `|` is in use in the wild as a delimiter,
      for instance in man pages for GNU awk, GNU grep, and GNU rcs.  Weaning
      people off of it (because it is a valid character in a numeric
      expression, and GNU troff has never accepted most other such
      characters as delimeters,{*} whereas AT&T troff accepted them all)
      looks to be a multi-stage, multi-year process.

    Fixes <https://savannah.gnu.org/bugs/?66481>.  Thanks to Paul Eggert for
    the report.

    {*} For distorted values of "most"--both GNU and AT&T troffs accept any
        basic Latin letter ([A-Za-z]) as a delimiter, a collection of 52
        exceptions that quantitatively swallows the rule.  Pragmatically,
        few *roff document authors past or present seem to have been
        adventurous enough to exercise this freedom.


G. Branden Robinson <gbranden>
Group administrator
Thu 25 Jul 2024 09:13:28 PM UTC, comment #1: 


commit b0dfb7901897eed5f54b64557be72263bd670245
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Sat Jul 20 16:15:45 2024 -0500

    [docs]: Note prohibition of `|` as a delimiter.

commit c8625529c8e8c565522460c8d57182a9beb0c24c
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
Date:   Sat Jul 20 16:10:45 2024 -0500

    [troff]: Fix Savannah #66009 (`|` not delimiter).

    * src/roff/troff/input.cpp (is_char_usable_as_delimiter): Reject `|`.

    Fixes <https://savannah.gnu.org/bugs/?66009>.


G. Branden Robinson <gbranden>
Group administrator
Sat 20 Jul 2024 09:10:05 PM UTC, original submission:  

My revamp of numerical expression handling exposed a bug.

`|` was being accepted as a delimiter in conditional expressions (for formatted output and string comparisons), but should not have been.

Why?

Because it is a valid character in a numeric expression, which conditional expressions also interpret.

Example:


.sp |432u


DWB 3.3, Heirloom Doctools, and Solaris 10 _troff_s all fail to interpret `|` as a delimiter.


$ echo '.if |foo|foo| .tm they are the same' | nroff


...silently exits without output in all of them.

G. Branden Robinson <gbranden>
Group administrator

 

Attached Files

This item currently has no attached files.

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by gbranden (interested party)
  • -email is unavailable- added by gbranden (Submitted the item)
  •  

    Votes

    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.

     

    History

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-12-04 gbranden Carbon-Copy- Added eggert
    2024-11-30 gbranden StatusNone Postponed
    2024-11-30 gbranden StatusFixed None
        Open/ClosedClosed Open
        Planned Release1.24.0 None
    2024-07-25 gbranden StatusIn Progress Fixed
        Open/ClosedOpen Closed
        Planned ReleaseNone 1.24.0

    Back to the top

    Powered by Savane 3.16-ed84.
    Corresponding source code