From patchwork Tue Feb 23 02:38:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 81369 Received: from mx01.colomx.prod.int.phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1N2fYZP021598 for ; Tue, 23 Feb 2010 02:42:09 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx01.colomx.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1N2d1Fj022510; Mon, 22 Feb 2010 21:39:03 -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 o1N2d0EP029292 for ; Mon, 22 Feb 2010 21:39:00 -0500 Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1N2ctFk002765; Mon, 22 Feb 2010 21:38:55 -0500 Received: from mx1.suse.de (cantor.suse.de [195.135.220.2]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1N2cdtd013114; Mon, 22 Feb 2010 21:38:40 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id 2804E8E8CC; Tue, 23 Feb 2010 03:38:39 +0100 (CET) From: Neil Brown To: heinzm@redhat.com Date: Tue, 23 Feb 2010 13:38:33 +1100 MIME-Version: 1.0 Message-ID: <19331.16297.375514.579107@notabene.brown> X-face: [Gw_3E*Gng}4rRrKRYotwlE?.2|**#s9D List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 23 Feb 2010 02:42:09 +0000 (UTC) --- dmraid.orig/include/dmraid/misc.h +++ dmraid/include/dmraid/misc.h @@ -18,6 +18,7 @@ extern void libdmraid_exit(struct lib_co extern void sysfs_workaround(struct lib_context *lc); extern void mk_alpha(struct lib_context *lc, char *str, size_t len); +extern void mk_alphanum(struct lib_context *lc, char *str, size_t len); extern char *get_basename(struct lib_context *lc, char *str); extern char *get_dirname(struct lib_context *lc, char *str); extern char *remove_white_space(struct lib_context *lc, char *str, size_t len); --- dmraid.orig/lib/format/ataraid/isw.c +++ dmraid/lib/format/ataraid/isw.c @@ -169,6 +169,7 @@ static size_t _name(struct lib_context *lc, struct isw *isw, char *str, size_t len, enum name_type nt, int num, struct isw_dev *dev, struct raid_dev *rd) { + int n; struct { const char *fmt, *what; } formats[] = { @@ -189,7 +190,11 @@ _name(struct lib_context *lc, struct isw f += (is_raid10(dev) ? 1 : 0); } - return snprintf(str, len, f->fmt, isw->family_num, f->what, num); + n = snprintf(str, len, f->fmt, isw->family_num, f->what, num); + /* As '->volume' could contain anything, we need to sanitise the name */ + if (str) + mk_alphanum(lc, str, n); + return n; } static char * --- dmraid.orig/lib/format/ddf/ddf1.c +++ dmraid/lib/format/ddf/ddf1.c @@ -689,6 +689,7 @@ name(struct lib_context *lc, struct ddf1 i = prefix + 16; while (!isgraph(buf[--i])); buf[i + 1] = 0; + mk_alphanum(lc, buf, i); } else { char *b; --- dmraid.orig/lib/misc/misc.c +++ dmraid/lib/misc/misc.c @@ -66,6 +66,20 @@ mk_alpha(struct lib_context *lc, char *s } } +/* Convert a string to only have alphanum or '-' or '_'. + * All others become '_' + */ +void +mk_alphanum(struct lib_context *lc, char *str, size_t len) +{ + for (; len && *str; len--, str++) { + if (!isalnum(*str) && + *str != '-' && + *str != '_') + *str = '_'; + } +} + /* Remove any whitespace from a string. */ char * remove_white_space(struct lib_context *lc, char *str, size_t size)