NetBSD Problem Report #52902

From www@NetBSD.org  Fri Jan  5 13:56:18 2018
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 7DE097A1B2
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  5 Jan 2018 13:56:18 +0000 (UTC)
Message-Id: <20180105135616.333FC7A218@mollari.NetBSD.org>
Date: Fri,  5 Jan 2018 13:56:16 +0000 (UTC)
From: kusumi.tomohiro@gmail.com
Reply-To: kusumi.tomohiro@gmail.com
To: gnats-bugs@NetBSD.org
Subject: dm: Avoid junk at the end of each line in dmsetup(8) output
X-Send-Pr-Version: www-1.0

>Number:         52902
>Category:       kern
>Synopsis:       dm: Avoid junk at the end of each line in dmsetup(8) output
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 05 14:00:00 +0000 2018
>Originator:     Tomohiro Kusumi
>Release:        -current, but existed since before
>Organization:
>Environment:
Architecture independent.
# uname -r
8.99.9

>Description:
Although having never looked at details of prop_dictionary_util(3)
source, it seems "prop_dictionary_t target_dict" must not be left
without being initialized with C string even if it's a blank string
possibly after prop_dictionary_set_int32(). Otherwise one will see
a junk byte at the end of each line in dmsetup(8) status output.

>How-To-Repeat:
See below dmsetup example using a meaningless dm-linear mapping,
just to showcase irrelevant junk bytes.

 # cat ./table.txt
 0 1000 linear /dev/sd1a 0
 1000 2000 linear /dev/sd1a 1000
 2000 3000 linear /dev/sd1a 2000
 3000 4000 linear /dev/sd1a 3000
 4000 5000 linear /dev/sd1a 4000
 # dmsetup create linear1 ./table.txt
 create and load called
 # dmsetup status /dev/mapper/linear1 > dmsetup_status.out

The screenshot below shows dmsetup_status.out file has an irrelevant
binary appended at the end of each line.
https://leaf.dragonflybsd.org/~tkusumi/diff/netbsd/dm_setup_eol_junk.PNG

The first od output below shows there is something before LF, while
the second one with this fix applied has no such bytes appended.

 # od -tx1z -Ax ./dmsetup_status.out
 000000 30 20 31 30 30 30 20 6c 69 6e 65 61 72 20 03 0a  >0 1000 linear ..<
 000010 31 30 30 30 20 32 30 30 30 20 6c 69 6e 65 61 72  >1000 2000 linear<
 000020 20 07 0a 32 30 30 30 20 33 30 30 30 20 6c 69 6e  > ..2000 3000 lin<
 000030 65 61 72 20 0b 0a 33 30 30 30 20 34 30 30 30 20  >ear ..3000 4000 <
 000040 6c 69 6e 65 61 72 20 0f 0a 34 30 30 30 20 35 30  >linear ..4000 50<
 000050 30 30 20 6c 69 6e 65 61 72 20 0a                 >00 linear .<
 00005b
 # od -tx1z -Ax ./dmsetup_status_fixed.out
 000000 30 20 31 30 30 30 20 6c 69 6e 65 61 72 20 0a 31  >0 1000 linear .1<
 000010 30 30 30 20 32 30 30 30 20 6c 69 6e 65 61 72 20  >000 2000 linear <
 000020 0a 32 30 30 30 20 33 30 30 30 20 6c 69 6e 65 61  >.2000 3000 linea<
 000030 72 20 0a 33 30 30 30 20 34 30 30 30 20 6c 69 6e  >r .3000 4000 lin<
 000040 65 61 72 20 0a 34 30 30 30 20 35 30 30 30 20 6c  >ear .4000 5000 l<
 000050 69 6e 65 61 72 20 0a                             >inear .<
 000057

>Fix:
https://leaf.dragonflybsd.org/~tkusumi/diff/netbsd/dm-3.patch

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-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.