From owner-svn-src-all@FreeBSD.ORG Tue Apr 16 19:58:24 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E6E18C8; Tue, 16 Apr 2013 19:58:24 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id BFCBC1397; Tue, 16 Apr 2013 19:58:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3GJwOYF084816; Tue, 16 Apr 2013 19:58:24 GMT (envelope-from ivoras@svn.freebsd.org) Received: (from ivoras@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3GJwO2h084815; Tue, 16 Apr 2013 19:58:24 GMT (envelope-from ivoras@svn.freebsd.org) Message-Id: <201304161958.r3GJwO2h084815@svn.freebsd.org> From: Ivan Voras Date: Tue, 16 Apr 2013 19:58:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249564 - head/sys/geom/label X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Apr 2013 19:58:25 -0000 Author: ivoras Date: Tue Apr 16 19:58:24 2013 New Revision: 249564 URL: http://svnweb.freebsd.org/changeset/base/249564 Log: Fix the buffer-overflow-fixing fixes. Pointy-hat to: me, for not realizing snprintf() is available in kernel. Thanks to: jh, for bringing me the good news of snprintf(), Pawel Worach, for noting that the panic can be provoked in i386 and not in amd64 Modified: head/sys/geom/label/g_label_disk_ident.c Modified: head/sys/geom/label/g_label_disk_ident.c ============================================================================== --- head/sys/geom/label/g_label_disk_ident.c Tue Apr 16 19:39:27 2013 (r249563) +++ head/sys/geom/label/g_label_disk_ident.c Tue Apr 16 19:58:24 2013 (r249564) @@ -40,38 +40,41 @@ __FBSDID("$FreeBSD$"); #define G_LABEL_DISK_IDENT_DIR "diskid" -static char* classes_pass[] = { G_DISK_CLASS_NAME, G_MULTIPATH_CLASS_NAME, NULL }; +static char* classes_pass[] = { G_DISK_CLASS_NAME, G_MULTIPATH_CLASS_NAME, + NULL }; static void g_label_disk_ident_taste(struct g_consumer *cp, char *label, size_t size) { struct g_class *cls; char ident[100]; - int ident_len = sizeof(ident); + int ident_len, found, i; g_topology_assert_not(); label[0] = '\0'; cls = cp->provider->geom->class; - /* Get the GEOM::ident string and construct a label in the format CLASS_NAME-ident */ + /* + * Get the GEOM::ident string, and construct a label in the format + * "CLASS_NAME-ident" + */ + ident_len = sizeof(ident); if (g_io_getattr("GEOM::ident", cp, &ident_len, ident) == 0) { - int i, found = 0; - if (ident_len == 0 || ident[0] == '\0') return; - for (i = 0; classes_pass[i] != NULL; i++) - if (strcmp(classes_pass[i], cls->name) == 0) + for (i = 0, found = 0; classes_pass[i] != NULL; i++) + if (strcmp(classes_pass[i], cls->name) == 0) { found = 1; + break; + } if (!found) return; - if (strlen(cls->name) + ident_len + 2 > size) - ident[ident_len - strlen(cls->name) - 2] = '\0'; - else - ident[ident_len] = '\0'; - strcpy(label, cls->name); - strcat(label, "-"); - strcat(label, ident); + /* + * We can safely ignore the result of strncpy; the label will + * simply be truncated, which at most is only annoying. + */ + (void)snprintf(label, size, "%s-%s", cls->name, ident); } } @@ -81,4 +84,5 @@ struct g_label_desc g_label_disk_ident = .ld_enabled = 1 }; -G_LABEL_INIT(disk_ident, g_label_disk_ident, "Create device nodes for drives which export a disk identification string"); +G_LABEL_INIT(disk_ident, g_label_disk_ident, "Create device nodes for drives " + "which export a disk identification string");