mpiexec bug fix

Kai Germaschewski kai.germaschewski at unh.edu
Thu Apr 21 20:53:13 EDT 2005


Hi,

after some non too trivial debugging, I tracked down a bug in
mpiexec-0.79. The symptoms were a seg fault when trying to use mpiexec
with a long command line on a Linux x86_64 system. (First thing which
wasn't so easy to figure was that the command line length was the
trigger).

The growstr_printf() function doesn't get the varargs handling right -- in 
case the string size isn't long enough, more space is allocated and the 
vnsprintf() call is repeated, however, we don't reinitialize the va_list, 
which then causes the seg fault.

The fix is simple, the attached patch also fixes a small inconsistency, 
where each string would be grown twice right away, which doesn't seem 
intended.

--Kai

diff -ur mpiexec-0.79.orig/growstr.c mpiexec-0.79/growstr.c
--- mpiexec-0.79.orig/growstr.c	2005-04-12 14:22:00.000000000 -0400
+++ mpiexec-0.79/growstr.c	2005-04-21 20:41:00.733002160 -0400
@@ -50,7 +50,6 @@
 growstr_init(void)
 {
     growstr_t *g = growstr_init_empty();
-    growstr_grow(g);
     return g;
 }
 
@@ -103,17 +102,18 @@
     va_list ap;
     growstr_t *h = growstr_init();
 
-    va_start(ap, format);
     for (;;) {
-	int n = vsnprintf(h->s, h->max, format, ap);
+	int n;
+	va_start(ap, format);
+	n = vsnprintf(h->s, h->max-1, format, ap);
 	if (n < h->max) {
 	    h->len = n;
 	    break;
 	}
 	while (n >= h->max)
 	    growstr_grow(h);
+	va_end(ap);
     }
-    va_end(ap);
     growstr_append(g, h->s);
     growstr_free(h);
 }




More information about the mpiexec mailing list