From patchwork Wed Feb 12 16:21:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 3641291 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3DB52BF13A for ; Wed, 12 Feb 2014 22:26:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7B81020145 for ; Wed, 12 Feb 2014 22:26:15 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id 4A90520142 for ; Wed, 12 Feb 2014 22:26:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1CMMMA5012271; Wed, 12 Feb 2014 17:22:24 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1CMML59024386 for ; Wed, 12 Feb 2014 17:22:21 -0500 Received: from ask-08.lab.msp.redhat.com (ask-08.lab.msp.redhat.com [10.15.85.8]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1CMMIVt010835 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 12 Feb 2014 17:22:20 -0500 Received: from ask-08.lab.msp.redhat.com (localhost [127.0.0.1]) by ask-08.lab.msp.redhat.com (8.14.6/8.14.6) with ESMTP id s1CGLoPa013361; Wed, 12 Feb 2014 10:21:50 -0600 Received: (from root@localhost) by ask-08.lab.msp.redhat.com (8.14.6/8.14.6/Submit) id s1CGLokk013360; Wed, 12 Feb 2014 10:21:50 -0600 From: Benjamin Marzinski To: device-mapper development Date: Wed, 12 Feb 2014 10:21:50 -0600 Message-Id: <1392222110-13324-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH] libmultipath: Don't chop const strings X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP multipath was chopping sysfs attr strings in order to make sure that ending whitespace didn't cause them to overflow their buffer. However those strings were const strings. This patch makes multipath check how much of the string length is ending whitespace, so that it can tell if it will really overflow the buffer without chopping the const string. Signed-off-by: Benjamin Marzinski Acked-by: Hannes Reinecke --- libmultipath/discovery.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 228ffd3..a6ff658 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -4,6 +4,7 @@ * Copyright (c) 2005 Mike Anderson */ #include +#include #include #include #include @@ -143,6 +144,7 @@ path_discovery (vector pathvec, struct config * conf, int flag) extern ssize_t \ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ { \ + int l; \ const char * attr; \ const char * devname; \ \ @@ -157,12 +159,14 @@ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ devname, #fname); \ return -ENXIO; \ } \ - if (strchop(attr) > len) { \ + for (l = strlen(attr); l >= 1 && isspace(attr[l-1]); l--); \ + if (l > len) { \ condlog(3, "%s: overflow in attribute %s", \ devname, #fname); \ return -EINVAL; \ } \ - return strlcpy(buff, attr, len); \ + strlcpy(buff, attr, len); \ + return strchop(buff); \ } declare_sysfs_get_str(devtype);