discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* bug report: assertion failure in print_otag
@ 2025-05-06 18:15 Michael Stapelberg
       [not found] ` <CANnVG6nMz7wxdLHxZJV4=pT4Dhr6OCJ__JMV90ruNb4c6DCyag@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Stapelberg @ 2025-05-06 18:15 UTC (permalink / raw)
  To: discuss

[-- Attachment #1: Type: text/plain, Size: 1910 bytes --]

Hello

I have recently encountered what I think is a bug in mandoc.
Here are the steps to reproduce with a minimal man page
and mandoc built from current CVS:

% cat > /tmp/minimal <<'EOT'
.Dd December  9, 2024
.ds doc-volume-operating-system OSSP
.Dt UUID 3ossp
.Os ossp-uuid 1.6.4
.
.Sh SYNOPSIS
.In uuid.h
.Nm foobar
.
EOT

% mandoc -Thtml /tmp/minimal
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <style>
    table.head, table.foot { width: 100%; }
    td.head-rtitle, td.foot-os { text-align: right; }
    td.head-vol { text-align: center; }
    .Nd, .Bf, .Op { display: inline; }
    .Pa, .Ad { font-style: italic; }
    .Ms { font-weight: bold; }
    .Bl-diag > dt { font-weight: bold; }
    code.Nm, .Fl, .Cm, .Ic, code.In, .Fd, .Fn, .Cd { font-weight: bold;
      font-family: inherit; }
  </style>
  <title>UUID(3ossp)</title>
</head>
<body>
<div class="head" role="doc-pageheader" aria-label="Manual header
  line"><span class="head-ltitle">UUID(3ossp)</span>
  <span class="head-vol">3ossp</span>
  <span class="head-rtitle">UUID(3ossp)</span></div>
<main class="manual-text">
<section class="Sh">
<h2 class="Sh" id="SYNOPSIS"><a class="permalink"
href="#SYNOPSIS">SYNOPSIS</a></h2>
<p class="Pp"><code class="In">#include
  &lt;<a class="In">uuid.h</a>&gt;</code></p>
mandoc: html.c:650: print_otag: Assertion `(htmltags[t->tag].flags &
HTML_TOPHRASE) == 0' failed.
zsh: IOT instruction (core dumped)  mandoc -Thtml /tmp/minimal

Maybe this man page is doing something weird, but either way,
mandoc should report an error instead of an assertion.

In case I shortened the minimal reproducer too much,
I have attached the full original man page.
You can find more details/context at:
https://github.com/Debian/debiman/issues/186#issuecomment-2855484050

Thanks in advance for having a look
Best regards
Michael

[-- Attachment #2: uuid.3ossp.en.gz --]
[-- Type: application/gzip, Size: 7444 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: bug report: assertion failure in print_otag
       [not found] ` <CANnVG6nMz7wxdLHxZJV4=pT4Dhr6OCJ__JMV90ruNb4c6DCyag@mail.gmail.com>
@ 2025-12-28 16:37   ` Michael Stapelberg
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Stapelberg @ 2025-12-28 16:37 UTC (permalink / raw)
  To: discuss

[-- Attachment #1: Type: text/plain, Size: 2841 bytes --]

I had another look at this issue and came up with the patch you can
find attached.

The regression test fails without the code change (mandoc runs into
the assertion)
and passes with the code change.

Feel free to change this suggestion as you see fit,
but I hope the patch helps get this crash fixed.

Thank you

On Wed, 23 Jul 2025 at 08:11, Michael Stapelberg <stapelberg@debian.org> wrote:
>
> While doing some server maintenance, I saw more crash dumps and was reminded of this bug.
>
> It would be great if someone could take a look and suggest a fix or workaround :)
>
> Thanks in advance
>
> On Tue, 6 May 2025 at 20:15, Michael Stapelberg <stapelberg@debian.org> wrote:
>>
>> Hello
>>
>> I have recently encountered what I think is a bug in mandoc.
>> Here are the steps to reproduce with a minimal man page
>> and mandoc built from current CVS:
>>
>> % cat > /tmp/minimal <<'EOT'
>> .Dd December  9, 2024
>> .ds doc-volume-operating-system OSSP
>> .Dt UUID 3ossp
>> .Os ossp-uuid 1.6.4
>> .
>> .Sh SYNOPSIS
>> .In uuid.h
>> .Nm foobar
>> .
>> EOT
>>
>> % mandoc -Thtml /tmp/minimal
>> <!DOCTYPE html>
>> <html>
>> <head>
>>   <meta charset="utf-8"/>
>>   <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
>>   <style>
>>     table.head, table.foot { width: 100%; }
>>     td.head-rtitle, td.foot-os { text-align: right; }
>>     td.head-vol { text-align: center; }
>>     .Nd, .Bf, .Op { display: inline; }
>>     .Pa, .Ad { font-style: italic; }
>>     .Ms { font-weight: bold; }
>>     .Bl-diag > dt { font-weight: bold; }
>>     code.Nm, .Fl, .Cm, .Ic, code.In, .Fd, .Fn, .Cd { font-weight: bold;
>>       font-family: inherit; }
>>   </style>
>>   <title>UUID(3ossp)</title>
>> </head>
>> <body>
>> <div class="head" role="doc-pageheader" aria-label="Manual header
>>   line"><span class="head-ltitle">UUID(3ossp)</span>
>>   <span class="head-vol">3ossp</span>
>>   <span class="head-rtitle">UUID(3ossp)</span></div>
>> <main class="manual-text">
>> <section class="Sh">
>> <h2 class="Sh" id="SYNOPSIS"><a class="permalink"
>> href="#SYNOPSIS">SYNOPSIS</a></h2>
>> <p class="Pp"><code class="In">#include
>>   &lt;<a class="In">uuid.h</a>&gt;</code></p>
>> mandoc: html.c:650: print_otag: Assertion `(htmltags[t->tag].flags &
>> HTML_TOPHRASE) == 0' failed.
>> zsh: IOT instruction (core dumped)  mandoc -Thtml /tmp/minimal
>>
>> Maybe this man page is doing something weird, but either way,
>> mandoc should report an error instead of an assertion.
>>
>> In case I shortened the minimal reproducer too much,
>> I have attached the full original man page.
>> You can find more details/context at:
>> https://github.com/Debian/debiman/issues/186#issuecomment-2855484050
>>
>> Thanks in advance for having a look
>> Best regards
>> Michael
>
>
>
> --
> Best regards,
> Michael



-- 
Best regards,
Michael

[-- Attachment #2: 0001-fix-crash-in-HTML-output-when-.In-is-followed-by-.Nm.patch --]
[-- Type: text/x-patch, Size: 3501 bytes --]

From 16126711d1473a17e00a76f9813a5e44d4ade21b Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <stapelberg@debian.org>
Date: Sun, 28 Dec 2025 17:28:53 +0100
Subject: [PATCH] fix crash (in HTML output) when .In is followed by .Nm in
 SYNOPSIS

When .In is followed by .Nm in the SYNOPSIS section, mandoc crashes
with an assertion failure:

  html.c:650: print_otag: Assertion `(htmltags[t->tag].flags &
  HTML_TOPHRASE) == 0' failed

This is because synopsis_pre() opens a <p> tag, and then mdoc_nm_pre()
tries to output a <table> inside that paragraph, but <table> elements
cannot appear in phrasing context.

The easiest fix seems to be to not call synopsis_pre from mdoc_nm_pre.
---
 mdoc_html.c                     |  1 -
 regress/mdoc/In/Makefile        |  3 ++-
 regress/mdoc/In/nm.in           | 16 ++++++++++++++++
 regress/mdoc/In/nm.out_ascii    | 14 ++++++++++++++
 regress/mdoc/In/nm.out_html     |  2 ++
 regress/mdoc/In/nm.out_markdown | 16 ++++++++++++++++
 6 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 regress/mdoc/In/nm.in
 create mode 100644 regress/mdoc/In/nm.out_ascii
 create mode 100644 regress/mdoc/In/nm.out_html
 create mode 100644 regress/mdoc/In/nm.out_markdown

diff --git a/mdoc_html.c b/mdoc_html.c
index 8ac3884..72b21ca 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -669,7 +669,6 @@ mdoc_nm_pre(MDOC_ARGS)
 		abort();
 	}
 	html_close_paragraph(h);
-	synopsis_pre(h, n);
 	print_otag(h, TAG_TABLE, "c", "Nm");
 	print_otag(h, TAG_TR, "");
 	return 1;
diff --git a/regress/mdoc/In/Makefile b/regress/mdoc/In/Makefile
index 9148e5f..ec1ec5f 100644
--- a/regress/mdoc/In/Makefile
+++ b/regress/mdoc/In/Makefile
@@ -1,6 +1,7 @@
 # $OpenBSD: Makefile,v 1.10 2024/09/21 11:56:36 schwarze Exp $
 
-REGRESS_TARGETS	 = break eos font noarg parse
+REGRESS_TARGETS	 = break eos font noarg parse nm
+HTML_TARGETS	 = nm
 LINT_TARGETS	 = noarg
 
 .include <bsd.regress.mk>
diff --git a/regress/mdoc/In/nm.in b/regress/mdoc/In/nm.in
new file mode 100644
index 0000000..e4bc886
--- /dev/null
+++ b/regress/mdoc/In/nm.in
@@ -0,0 +1,16 @@
+.Dd December  9, 2024
+.ds doc-volume-operating-system OSSP
+.Dt UUID 3ossp
+.Os ossp-uuid 1.6.4
+.
+.Sh SYNOPSIS
+.In uuid.h
+.Nm foobar
+.
+BEGINTEST
+
+mandoc successfully
+
+rendered to HTML
+
+ENDTEST
diff --git a/regress/mdoc/In/nm.out_ascii b/regress/mdoc/In/nm.out_ascii
new file mode 100644
index 0000000..9e11d88
--- /dev/null
+++ b/regress/mdoc/In/nm.out_ascii
@@ -0,0 +1,14 @@
+UUID(3ossp)                          LOCAL                         UUID(3ossp)
+
+S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
+     #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<u\buu\bui\bid\bd.\b.h\bh>\b>
+
+     f\bfo\boo\bob\bba\bar\br BEGINTEST
+
+            mandoc successfully
+
+            rendered to HTML
+
+            ENDTEST
+
+ossp-uuid 1.6.4                December 9, 2024                    UUID(3ossp)
diff --git a/regress/mdoc/In/nm.out_html b/regress/mdoc/In/nm.out_html
new file mode 100644
index 0000000..8ab9a8c
--- /dev/null
+++ b/regress/mdoc/In/nm.out_html
@@ -0,0 +1,2 @@
+    <p class="Pp">mandoc successfully</p>
+    <p class="Pp">rendered to HTML</p>
diff --git a/regress/mdoc/In/nm.out_markdown b/regress/mdoc/In/nm.out_markdown
new file mode 100644
index 0000000..19aba84
--- /dev/null
+++ b/regress/mdoc/In/nm.out_markdown
@@ -0,0 +1,16 @@
+UUID(3ossp) - LOCAL
+
+# SYNOPSIS
+
+**#include &lt;uuid.h>**
+
+**foobar**
+BEGINTEST
+
+mandoc successfully
+
+rendered to HTML
+
+ENDTEST
+
+ossp-uuid 1.6.4 - December 9, 2024 - UUID(3ossp)
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-28 16:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 18:15 bug report: assertion failure in print_otag Michael Stapelberg
     [not found] ` <CANnVG6nMz7wxdLHxZJV4=pT4Dhr6OCJ__JMV90ruNb4c6DCyag@mail.gmail.com>
2025-12-28 16:37   ` Michael Stapelberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).