Skip to contentSkip to conversation

shared segtypes loading

DISCUSSION [email protected] 2 participants 3 messages Feb 7, 2007 – Feb 8, 2007

lore
Share & tools
lore
#0 lore raw

I'm new to this list, but a longtime user of lvm. My brief googling for this problem turned up nothing, but if it has been discussed before, please tell me to RTFA and I'll look harder.

I believe I may have found a bug in the dynamic loading of segtypes in toolcontext.c. I've posted a bunch of details at
http://bugs.gentoo.org/show_bug.cgi?id=131662
but I'll summarize here to conserve your time.

When segtypes are loaded dynamically, _init_segtypes first adds them to cmd->segtypes:

        list_add(&cmd->segtypes, &segtype->list);

and then iterates over that same list, looking for a duplicate name:

        list_iterate_safe(sgtl, tmp, &cmd->segtypes) {
                segtype2 = list_item(sgtl, struct segment_type);
                if (!strcmp(segtype2->name, segtype->name)) {
                        log_error("Duplicate segment type %s: "
                                  ...

from my understanding, under any circumstances that this code is executed, at some point segtype2 == segtype, and thus the strcmp() returns zero.

I fixed this locally with a patch (attached to the above Gentoo ticket) tht just moves the list_add() below the duplicate check. This seems effective, but the would-never-have-worked nature of this bug (and age of the relevant code) makes me suspect I'm missing something.

Dustin

#1 lore raw
Quoted 22 lines · dustin at v.igoro.us

I'm new to this list, but a longtime user of lvm. My brief googling for this problem turned up nothing, but if it has been discussed before, please tell me to RTFA and I'll look harder.

I believe I may have found a bug in the dynamic loading of segtypes in toolcontext.c. I've posted a bunch of details at
http://bugs.gentoo.org/show_bug.cgi?id=131662
but I'll summarize here to conserve your time.

When segtypes are loaded dynamically, _init_segtypes first adds them to cmd->segtypes:

        list_add(&cmd->segtypes, &segtype->list);

and then iterates over that same list, looking for a duplicate name:

        list_iterate_safe(sgtl, tmp, &cmd->segtypes) {
                segtype2 = list_item(sgtl, struct segment_type);
                if (!strcmp(segtype2->name, segtype->name)) {
                        log_error("Duplicate segment type %s: "
                                  ...
Quoted 8 lines

from my understanding, under any circumstances that this code is executed, at some point segtype2 == segtype, and thus the strcmp() returns zero.

I fixed this locally with a patch (attached to the above Gentoo ticket) tht just moves the list_add() below the duplicate check. This seems effective, but the would-never-have-worked nature of this bug (and age of the relevant code) makes me suspect I'm missing something.

Moving the add below the list_iterate_safe will still add it to the list even if there's a duplicate right? So maybe the right thing is something like this:

lib/commands/toolcontext.c +2 -1
Index: LVM2/lib/commands/toolcontext.c
===================================================================
@@ -777,7 +777,8 @@ static int _init_segtypes(struct cmd_con
 
 			list_iterate_safe(sgtl, tmp, &cmd->segtypes) {
 				segtype2 = list_item(sgtl, struct segment_type);
-				if (!strcmp(segtype2->name, segtype->name)) {
+				if ( (segtype2 != segtype) &&
+				     !strcmp(segtype2->name, segtype->name)) {
 					log_error("Duplicate segment type %s: "
 						  "unloading shared library %s",
 						  segtype->name, cv->v.str);
#2 lore raw
Quoted 9 lines · Dave Wysochanski

Moving the add below the list_iterate_safe will still add it to the list even if there's a duplicate right? So maybe the right thing is something like this:

Index: LVM2/lib/commands/toolcontext.c
===================================================================

lib/commands/toolcontext.c static int _init_segtypes(struct cmd_con · line 784

Quoted 9 lines
lib/commands/toolcontext.c +2 -1
@@ -777,7 +777,8 @@ static int _init_segtypes(struct cmd_con
 
 			list_iterate_safe(sgtl, tmp, &cmd->segtypes) {
 				segtype2 = list_item(sgtl, struct segment_type);
-				if (!strcmp(segtype2->name, segtype->name)) {
+				if ( (segtype2 != segtype) &&
+				     !strcmp(segtype2->name, segtype->name)) {
 					log_error("Duplicate segment type %s: "
 						  "unloading shared library %s",
 						  segtype->name, cv->v.str);

Agreed, that would be better.

Dustin