Skip to contentSkip to conversation

dmraid/lib/format/ataraid jm.c

PATCH [email protected] 1 participant 1 message Sep 17, 2009 Device mapper

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/dm
Module name: dmraid
Changes by: [email protected] 2009-09-17 09:21:07

Modified files:
lib/format/ataraid: jm.c

Log message:
JMicron name termination fix

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/dmraid/lib/format/ataraid/jm.c.diff?cvsroot=dm&r1=1.4&r2=1.5

lib/format/ataraid/jm.c +9 -9
@@ -25,18 +25,18 @@
 static char *
 name(struct lib_context *lc, struct raid_dev *rd, unsigned int subset)
 {
-	int i;
-	size_t len;
+	size_t i, len;
 	struct jm *jm = META(rd, jm);
-	char buf[JM_NAME_LEN + 1], *ret, *name = (char *) jm->name;
+	char *ret, *name = (char *) jm->name;
+	char buf[JM_NAME_LEN + 1] = { '\0' };
 
-	/* Name always 0 terminated or whitespace at end ? */
+	/* Sanitize name, make sure it's null terminated */
 	strncpy(buf, name, JM_NAME_LEN);
-	len = strlen(buf);
-	i = len < JM_NAME_LEN ? len : JM_NAME_LEN;
-	buf[i] = 0;
-	while (i-- && isspace(buf[i]))
-		buf[i] = 0;
+	while (i && isspace(buf[i])) {
+		name[i]='\0';
+		buf[i]='\0';
+		--i;
+	}
 
 	len = strlen(buf) + sizeof(HANDLER) + (jm->mode == JM_T_RAID01 ? 3 : 2);
 	if ((ret = dbg_malloc(len))) {