Bug 260016 - devel/libtextstyle: calls tputs() with invalid string
Summary: devel/libtextstyle: calls tputs() with invalid string
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Tijl Coosemans
Depends on:
Reported: 2021-11-24 14:25 UTC by Adriaan de Groot
Modified: 2021-11-24 16:05 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (tijl)

Patch for ports-tree (1.84 KB, patch)
2021-11-24 14:25 UTC, Adriaan de Groot
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adriaan de Groot freebsd_committer 2021-11-24 14:25:48 UTC
Created attachment 229695 [details]
Patch for ports-tree

When libtextstyle outputs a hyperlink, on terminals that support hyperlinks, it outputs `\e]8;id=<id-part>;<url-part>;` . The id-part and the url-part are user-supplied (by the calling program). In a common case where the ID is NULL, libtextstyle invents one based on a simple hash. On my system, with bison as calling program, the hash is usually  `5b1...` (32 characters).

Libtextstyle outputs the escape-sequence by calling `tputs()` five times. It passes e.g. the id-part as a string to `tputs()`. From the tputs manpage, it seems that only terminal-escape codes should be passed in, or return-values from tparm(). In any case, when the string passed to `tputs()` starts with a digit, this is interpreted **on BSDs only** by ncurses as specifying a delay. The leading digits vanish from the output.

The attached patch replaces the `tputs()` calls with a call to write the strings to the output stream. This avoids any interpretation of the id-part and url that `tputs()` might do.

(I would never have noticed, but in combination with bugs in ncurses and specific terminal settings, this crashes bison; avoiding the ncurses bugs by patching libtextstyle fixes my bison crashes)

The attached patch applies to the ports-tree; it adds a single patch to replace tputs in the relevant routing with direct-writes. I suppose this warrants an exp-run (given the warning in the Makefile) and ought-to-be-upstreamed, but I don't know how to do the latter.
Comment 1 Adriaan de Groot freebsd_committer 2021-11-24 16:05:52 UTC
.. regardless, this was (also) fixed at the ncurses level in 9c15ec46bfb6558c42a668afeef1a4418dcd970d, PR 256731, but I was running an older 13- git version.