[dm-devel] dmraid/lib/format/ataraid jm.c

heinzm at sourceware.org heinzm at sourceware.org
Thu Sep 17 09:21:08 UTC 2009


CVSROOT:	/cvs/dm
Module name:	dmraid
Changes by:	heinzm at sourceware.org	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

--- dmraid/lib/format/ataraid/jm.c	2008/06/20 21:52:17	1.4
+++ dmraid/lib/format/ataraid/jm.c	2009/09/17 09:21:07	1.5
@@ -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))) {




More information about the dm-devel mailing list