NetBSD Problem Report #48438

From enami@sm.sony.co.jp  Tue Dec 10 08:44:16 2013
Return-Path: <enami@sm.sony.co.jp>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 20D8AA641B
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 10 Dec 2013 08:44:16 +0000 (UTC)
Message-Id: <20131210084321.DB3BF10A78@sigtrap.sm.sony.co.jp>
Date: Tue, 10 Dec 2013 17:43:21 +0900 (JST)
From: tsugutomo.enami@jp.sony.com
To: gnats-bugs@gnats.NetBSD.org
Subject: mandoc(1) fails to handle nested double quote correctly.
X-Send-Pr-Version: 3.95

>Number:         48438
>Category:       bin
>Synopsis:       mandoc(1) fails to handle nested double quote correctly.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 10 08:45:00 +0000 2013
>Closed-Date:    Tue Dec 17 09:28:31 +0000 2013
>Last-Modified:  Tue Dec 17 09:30:00 +0000 2013
>Originator:     enami tsugutomo
>Release:        NetBSD 6.1_STABLE
>Organization:
>Environment:
System: NetBSD sigtrap.sm.sony.co.jp 6.1_STABLE NetBSD 6.1_STABLE (GENERIC) #44: Mon Oct 21 17:13:31 JST 2013 enami@sigtrap.sm.sony.co.jp:/home/enami/src/netbsd-6/obj.amd64/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
mandoc(1) fails to handle nested double quote correctly.

>How-To-Repeat:

% cd /usr/src
% for c in 'nroff -mandoc' mandoc; do $c usr.bin/jot/jot.1; done | grep grep
           grep `jot -s "" -b . 80`
           grep `jot -s """" -b . 80`
%

The former is correct output by nroff -mandoc and the latter is incorrect
output by mandoc command.

>Fix:

Skip double qoute inside double quote like mandoc_getarg() does.

Index: dist/mdoc_argv.c
===================================================================
RCS file: /cvsroot/src/external/bsd/mdocml/dist/mdoc_argv.c,v
retrieving revision 1.4
diff -u -r1.4 mdoc_argv.c
--- dist/mdoc_argv.c	3 Apr 2013 14:50:26 -0000	1.4
+++ dist/mdoc_argv.c	10 Dec 2013 08:39:42 -0000
@@ -550,6 +550,7 @@
 	 */

 	if (MDOC_PHRASELIT & m->flags || '\"' == buf[*pos]) {
+		int pairs = 0;
 		if ( ! (MDOC_PHRASELIT & m->flags))
 			*v = &buf[++(*pos)];

@@ -557,11 +558,14 @@
 			m->flags |= MDOC_PHRASELIT;

 		for ( ; buf[*pos]; (*pos)++) {
+			if (pairs)
+				buf[*pos - pairs] = buf[*pos];
 			if ('\"' != buf[*pos])
 				continue;
 			if ('\"' != buf[*pos + 1])
 				break;
 			(*pos)++;
+			pairs++;
 		}

 		if ('\0' == buf[*pos]) {
@@ -572,7 +576,7 @@
 		}

 		m->flags &= ~MDOC_PHRASELIT;
-		buf[(*pos)++] = '\0';
+		buf[(*pos)++ - pairs] = '\0';

 		if ('\0' == buf[*pos])
 			return(ARGS_QWORD);

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Tue, 17 Dec 2013 09:28:31 +0000
State-Changed-Why:
Fixed in -current based on upstream's version of your patch.
Thank you!


From: "Thomas Klausner" <wiz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/48438 CVS commit: src/external/bsd/mdocml/dist
Date: Tue, 17 Dec 2013 09:28:11 +0000

 Module Name:	src
 Committed By:	wiz
 Date:		Tue Dec 17 09:28:10 UTC 2013

 Modified Files:
 	src/external/bsd/mdocml/dist: mdoc_argv.c

 Log Message:
 Fix handling of nested double quotes.

 From Ingo Schwarze <schwarze@usta.de> based on patch by enami@
 in PR 48438.


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/external/bsd/mdocml/dist/mdoc_argv.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.