From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jaegeuk Kim Subject: Re: [PATCH] libf2fs: quote non-printables when displaying "disk model" Date: Mon, 7 May 2018 14:58:11 -0700 Message-ID: <20180507215811.GA90393@jaegeuk-macbookpro.roam.corp.google.com> References: <20180506225014.28201-1-kilobyte@angband.pl> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fFo9C-0006BI-Ln for linux-f2fs-devel@lists.sourceforge.net; Mon, 07 May 2018 21:58:18 +0000 Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1fFo9B-008aQR-CD for linux-f2fs-devel@lists.sourceforge.net; Mon, 07 May 2018 21:58:18 +0000 Content-Disposition: inline In-Reply-To: <20180506225014.28201-1-kilobyte@angband.pl> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: Adam Borowski Cc: linux-f2fs-devel@lists.sourceforge.net On 05/07, Adam Borowski wrote: > One offender I own has: > STORAGE DEVICE 1404x05xe3x07QGENEx00%x00x00x00x00x00x00x00x00x00x00x00x00x170x04 > > I limited it to pure ASCII only, but you might want to allow high-bit bytes, > either validating UTF-8 or assuming that mojibake is not as bad as beep and > zeroes as in the above example. Or, cutting off at the first control > character might be a good alternative too. > > Signed-off-by: Adam Borowski > --- > lib/libf2fs.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/lib/libf2fs.c b/lib/libf2fs.c > index 5ef0214..8782afc 100644 > --- a/lib/libf2fs.c > +++ b/lib/libf2fs.c > @@ -884,8 +884,9 @@ int get_device_info(int i) > > MSG(0, "Info: [%s] Disk Model: ", > dev->path); > - while (reply_buffer[i] != '`' && i < 80) > - printf("%c", reply_buffer[i++]); > + for (; reply_buffer[i] != '`' && i < 80; i++) > + printf((reply_buffer[i] >= ' ' && reply_buffer[i] < 127) ? How about printing only valid characters here? In my virtualbox, this is showing garbage characters. Thanks, > + "%c" : "x%02x", reply_buffer[i]); > printf("\n"); > } > #endif > -- > 2.17.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot