From patchwork Fri Dec 11 03:22:57 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 66415 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBB3OV8U015603 for ; Fri, 11 Dec 2009 03:24:31 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 0DBB961B12E; Thu, 10 Dec 2009 22:24:31 -0500 (EST) Received: from int-mx03.intmail.prod.int.phx2.redhat.com (nat-pool.util.phx.redhat.com [10.8.5.200]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id nBB3OT6n029758 for ; Thu, 10 Dec 2009 22:24:29 -0500 Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.11]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBB3OTLR002572 for ; Thu, 10 Dec 2009 22:24:29 -0500 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBB3ODOA002866 for ; Thu, 10 Dec 2009 22:24:14 -0500 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 3FD8D9E4BF for ; Fri, 11 Dec 2009 04:24:13 +0100 (CET) From: NeilBrown To: dm-devel@redhat.com Date: Fri, 11 Dec 2009 14:22:57 +1100 Message-Id: <20091211032408.285980198@suse.de> User-Agent: quilt/0.48-1 References: <20091211032255.766079509@suse.de> Content-Disposition: inline; filename=snprint.fixes X-RedHat-Spam-Score: -4.267 (AWL,RCVD_IN_DNSWL_MED) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-Scanned-By: MIMEDefang 2.67 on 10.5.110.11 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH libdmraid-events 2/3] Fix some issues with use of snprintf X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development 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 --- libdmraid-events.orig/libdmraid-events.c +++ libdmraid-events/libdmraid-events.c @@ -303,6 +303,7 @@ static char *_match_port(const char *vol for(i = 0; i < curr->num_sata_drives; i++) if(curr->raid_mem[i].port_num>=0){ snprintf(port, 4, "%d", curr->raid_mem[i].port_num); + port[4] = 0; memcpy(buf+strlen(buf), curr->raid_mem[i].dev_name, strlen(curr->raid_mem[i].dev_name)); memcpy(buf+strlen(buf), "=", 1); memcpy(buf+strlen(buf), port, strlen(port)); @@ -378,7 +379,7 @@ static char *_get_dev_names(const char * int num = 0; FILE *fd; char sys_path[BUF_SIZE]; - char dm_num[2]; + char dm_num[5]; char dm_mm[MAJOR_MINOR]; char f_mm[MAJOR_MINOR]; struct dm_task *dmt; @@ -406,8 +407,10 @@ static char *_get_dev_names(const char * memset(sys_path, 0, BUF_SIZE); memcpy(sys_path, SYS_DM_PATH, strlen(SYS_DM_PATH)); memset(dm_mm, 0, MAJOR_MINOR); - snprintf(dm_mm, sizeof(info.major)+sizeof(info.minor), "%d:%d", info.major, info.minor); - snprintf(dm_num, sizeof(num = 0), "%d", num); + snprintf(dm_mm, MAJOR_MINOR-1, "%d:%d", info.major, info.minor); + num = 0; + snprintf(dm_num, sizeof(dm_num), "%d", num); + while(!access(strncat(sys_path, dm_num, strlen(dm_num)), F_OK)) { @@ -423,7 +426,8 @@ static char *_get_dev_names(const char * /* Reset string for next iteration */ memset(sys_path+strlen(SYS_DM_PATH), 0, 1); num++; - snprintf(dm_num, sizeof(num), "%d", num); + snprintf(dm_num, sizeof(dm_num), "%d", num); + dm_num[sizeof(dm_num)-1] = 0; fclose(fd); continue; }