Received: from eggs.gnu.org ([2001:4830:134:3::10]:37220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VcFaF-0003RN-6j for qemu-devel@nongnu.org; Fri, 01 Nov 2013 10:20:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VcFa6-0003qd-PB for qemu-devel@nongnu.org; Fri, 01 Nov 2013 10:20:19 -0400 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]:55378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VcFa6-0003qX-Hg for qemu-devel@nongnu.org; Fri, 01 Nov 2013 10:20:10 -0400 Received: by mail-pa0-f46.google.com with SMTP id rd3so4116398pab.19 for ; Fri, 01 Nov 2013 07:20:09 -0700 (PDT) Date: Fri, 01 Nov 2013 23:20:04 +0900 Message-ID: From: MORITA Kazutaka In-Reply-To: <1383198568-27528-3-git-send-email-namei.unix@gmail.com> References: <1383198568-27528-1-git-send-email-namei.unix@gmail.com> <1383198568-27528-3-git-send-email-namei.unix@gmail.com> MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Subject: Re: [Qemu-devel] [sheepdog] [PATCH v4 2/2] sheepdog: support user-defined redundancy option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Yuan Cc: Kevin Wolf , sheepdog@lists.wpkg.org, qemu-devel@nongnu.org, Stefan Hajnoczi At Thu, 31 Oct 2013 13:49:28 +0800, Liu Yuan wrote: > > +/* > + * Sheepdog support two kinds of redundancy, full replication and erasure > + * coding. > + * > + * # create a fully replicated vdi with x copies > + * -o redundancy=x (1 <= x <= SD_MAX_COPIES) > + * > + * # create a erasure coded vdi with x data strips and y parity strips > + * -o redundancy=x:y (x must be one of {2,4,8,16} and 1 <= y < SD_EC_MAX_STRIP) > + */ > +static int parse_redundancy(BDRVSheepdogState *s, const char *opt) > +{ > + struct SheepdogInode *inode = &s->inode; > + const char *n1, *n2; > + uint8_t copy, parity; > + char p[10]; > + > + strncpy(p, opt, sizeof(p)); strncpy() is not safe here. Please use pstrcpy() instead. > + n1 = strtok(p, ":"); > + n2 = strtok(NULL, ":"); > + > + if ((n1 && !is_numeric(n1)) || (n2 && !is_numeric(n2))) { > + return -EINVAL; > + } This cannot detect an error when 'opt' is empty. Actually, the following command causes a segfault. $ qemu-img create -o redundancy= sheepdog:test 4G Thanks, Kazutaka