changeset 5166:4866b8311a88 onnv_75

6610537 ipseckey error output can get mangled on x86 6610538 ipseckey can core dump with truncated input
author markfen
date Mon, 01 Oct 2007 22:40:41 -0700
parents 40a9055a6b98
children bb31f9669805
files usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ipseckey.c
diffstat 1 files changed, 26 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ipseckey.c	Mon Oct 01 22:31:20 2007 -0700
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ipsecutils/ipseckey.c	Mon Oct 01 22:40:41 2007 -0700
@@ -114,31 +114,37 @@
 	err_ptr = ep;
 
 	va_start(ap, fmt);
-	(void) vsnprintf(tmp_buff, sizeof (tmp_buff), fmt, ap);
+	length = vsnprintf(tmp_buff, sizeof (tmp_buff), fmt, ap);
 	va_end(ap);
 
+	/* There is a new line character */
+	length++;
+
 	if (ep == NULL) {
-		/*
-		 * This is the first error to record, get a
-		 * new buffer, copy in the command line that
-		 * triggered this error/warning.
-		 */
-		if (ebuf != NULL) {
-			length = strlen(ebuf);
-			err_ptr = calloc(length, sizeof (char));
-			if (err_ptr == NULL)
-				Bail("calloc() failed");
-			(void) strlcpy(err_ptr, ebuf, length);
-		}
-	} else {
-		length = strlen(ep);
+		if (ebuf != NULL)
+			length += strlen(ebuf);
+	} else  {
+		length += strlen(ep);
 	}
-	length += strlen(tmp_buff);
-	/* There is a new line character */
-	length++;
-	err_ptr = realloc(err_ptr, length);
+
+	if (err_ptr == NULL)
+		err_ptr = calloc(length, sizeof (char));
+	else
+		err_ptr = realloc(err_ptr, length);
+
 	if (err_ptr == NULL)
 		Bail("realloc() failure");
+
+	/*
+	 * If (ep == NULL) then this is the first error to record,
+	 * copy in the command line that triggered this error/warning.
+	 */
+	if (ep == NULL && ebuf != NULL)
+		(void) strlcpy(err_ptr, ebuf, length);
+
+	/*
+	 * Now the actual error.
+	 */
 	(void) strlcat(err_ptr, tmp_buff, length);
 	return (err_ptr);
 }
@@ -204,6 +210,7 @@
 		}
 		return;
 	}
+	EXIT_FATAL(NULL);
 }
 
 /*