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
This commit is contained in:
parent
c31105ae2f
commit
b7d8771305
@ -40,38 +40,41 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#define G_LABEL_DISK_IDENT_DIR "diskid"
|
#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
|
static void
|
||||||
g_label_disk_ident_taste(struct g_consumer *cp, char *label, size_t size)
|
g_label_disk_ident_taste(struct g_consumer *cp, char *label, size_t size)
|
||||||
{
|
{
|
||||||
struct g_class *cls;
|
struct g_class *cls;
|
||||||
char ident[100];
|
char ident[100];
|
||||||
int ident_len = sizeof(ident);
|
int ident_len, found, i;
|
||||||
|
|
||||||
g_topology_assert_not();
|
g_topology_assert_not();
|
||||||
label[0] = '\0';
|
label[0] = '\0';
|
||||||
|
|
||||||
cls = cp->provider->geom->class;
|
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) {
|
if (g_io_getattr("GEOM::ident", cp, &ident_len, ident) == 0) {
|
||||||
int i, found = 0;
|
|
||||||
|
|
||||||
if (ident_len == 0 || ident[0] == '\0')
|
if (ident_len == 0 || ident[0] == '\0')
|
||||||
return;
|
return;
|
||||||
for (i = 0; classes_pass[i] != NULL; i++)
|
for (i = 0, found = 0; classes_pass[i] != NULL; i++)
|
||||||
if (strcmp(classes_pass[i], cls->name) == 0)
|
if (strcmp(classes_pass[i], cls->name) == 0) {
|
||||||
found = 1;
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
return;
|
return;
|
||||||
if (strlen(cls->name) + ident_len + 2 > size)
|
/*
|
||||||
ident[ident_len - strlen(cls->name) - 2] = '\0';
|
* We can safely ignore the result of strncpy; the label will
|
||||||
else
|
* simply be truncated, which at most is only annoying.
|
||||||
ident[ident_len] = '\0';
|
*/
|
||||||
strcpy(label, cls->name);
|
(void)snprintf(label, size, "%s-%s", cls->name, ident);
|
||||||
strcat(label, "-");
|
|
||||||
strcat(label, ident);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,4 +84,5 @@ struct g_label_desc g_label_disk_ident = {
|
|||||||
.ld_enabled = 1
|
.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");
|
||||||
|
Loading…
Reference in New Issue
Block a user