changeset 19379:8c5ec23311fc

12165 lp: argument to 'alloca' may be too large Reviewed by: Matthias Scheler <mscheler@tintri.com> Approved by: Dan McDonald <danmcd@joyent.com>
author Toomas Soome <tsoome@me.com>
date Sat, 04 Jan 2020 20:29:28 +0200
parents bbdb2eb6f168
children b7b867e9322a
files usr/src/cmd/lp/lib/papi/service.c usr/src/lib/print/libpapi-dynamic/common/service.c usr/src/lib/print/libpapi-ipp/common/service.c usr/src/lib/print/libpapi-lpd/common/service.c
diffstat 4 files changed, 37 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/lp/lib/papi/service.c	Sat Jan 04 14:53:59 2020 +0200
+++ b/usr/src/cmd/lp/lib/papi/service.c	Sat Jan 04 20:29:28 2020 +0200
@@ -23,15 +23,10 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
-/*LINTLIBRARY*/
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
-#include <alloca.h>
 #include <libintl.h>
 #include <papi_impl.h>
 
@@ -284,20 +279,18 @@
 {
 	if ((svc != NULL) && (fmt != NULL)) {
 		va_list ap;
-		size_t size;
-		char *message = alloca(BUFSIZ);
+		char *message;
+		int rv;
 
 		va_start(ap, fmt);
-		/*
-		 * fill in the message.  If the buffer is too small, allocate
-		 * one that is large enough and fill it in.
-		 */
-		if ((size = vsnprintf(message, BUFSIZ, fmt, ap)) >= BUFSIZ)
-			if ((message = alloca(size)) != NULL)
-				vsnprintf(message, size, fmt, ap);
+		rv = vasprintf(&message, fmt, ap);
 		va_end(ap);
 
-		papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND,
-					"detailed-status-message", message);
+		if (rv >= 0) {
+			papiAttributeListAddString(&svc->attributes,
+			    PAPI_ATTR_APPEND, "detailed-status-message",
+			    message);
+			free(message);
+		}
 	}
 }
--- a/usr/src/lib/print/libpapi-dynamic/common/service.c	Sat Jan 04 14:53:59 2020 +0200
+++ b/usr/src/lib/print/libpapi-dynamic/common/service.c	Sat Jan 04 20:29:28 2020 +0200
@@ -27,17 +27,12 @@
 
 /* $Id: service.c 172 2006-05-24 20:54:00Z njacobs $ */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
-/*LINTLIBRARY*/
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <string.h>
-#include <alloca.h>
 #include <libintl.h>
 #include <papi_impl.h>
 #include <config-site.h>
@@ -550,23 +545,21 @@
 {
 	if ((svc != NULL) && (fmt != NULL)) {
 		va_list ap;
-		size_t size;
-		char *message = alloca(BUFSIZ);
+		char *message;
+		int rv;
 
 		va_start(ap, fmt);
-		/*
-		 * fill in the message.  If the buffer is too small, allocate
-		 * one that is large enough and fill it in.
-		 */
-		if ((size = vsnprintf(message, BUFSIZ, fmt, ap)) >= BUFSIZ)
-			if ((message = alloca(size)) != NULL)
-				vsnprintf(message, size, fmt, ap);
+		rv = vasprintf(&message, fmt, ap);
 		va_end(ap);
 
-		papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND,
-					"detailed-status-message", message);
+		if (rv >= 0) {
+			papiAttributeListAddString(&svc->attributes,
+			    PAPI_ATTR_APPEND, "detailed-status-message",
+			    message);
 #ifdef DEBUG
-		fprintf(stderr, "detailed_error(%s)\n", message);
+			fprintf(stderr, "detailed_error(%s)\n", message);
 #endif
+			free(message);
+		}
 	}
 }
--- a/usr/src/lib/print/libpapi-ipp/common/service.c	Sat Jan 04 14:53:59 2020 +0200
+++ b/usr/src/lib/print/libpapi-ipp/common/service.c	Sat Jan 04 20:29:28 2020 +0200
@@ -27,15 +27,10 @@
 
 /* $Id: service.c 171 2006-05-20 06:00:32Z njacobs $ */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
-/*LINTLIBRARY*/
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
-#include <alloca.h>
 #include <libintl.h>
 #include <papi_impl.h>
 
@@ -375,20 +370,18 @@
 {
 	if ((svc != NULL) && (fmt != NULL)) {
 		va_list ap;
-		size_t size;
-		char *message = alloca(BUFSIZ);
+		char *message;
+		int rv;
 
 		va_start(ap, fmt);
-		/*
-		 * fill in the message.  If the buffer is too small, allocate
-		 * one that is large enough and fill it in.
-		 */
-		if ((size = vsnprintf(message, BUFSIZ, fmt, ap)) >= BUFSIZ)
-			if ((message = alloca(size)) != NULL)
-				vsnprintf(message, size, fmt, ap);
+		rv = vasprintf(&message, fmt, ap);
 		va_end(ap);
 
-		papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND,
-					"detailed-status-message", message);
+		if (rv >= 0) {
+			papiAttributeListAddString(&svc->attributes,
+			    PAPI_ATTR_APPEND, "detailed-status-message",
+			    message);
+			free(message);
+		}
 	}
 }
--- a/usr/src/lib/print/libpapi-lpd/common/service.c	Sat Jan 04 14:53:59 2020 +0200
+++ b/usr/src/lib/print/libpapi-lpd/common/service.c	Sat Jan 04 20:29:28 2020 +0200
@@ -27,13 +27,10 @@
 
 /* $Id: service.c 163 2006-05-09 15:07:45Z njacobs $ */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
-#include <alloca.h>
 #include <uri.h>
 #include <papi_impl.h>
 
@@ -280,20 +277,18 @@
 {
 	if ((svc != NULL) && (fmt != NULL)) {
 		va_list ap;
-		size_t size;
-		char *message = alloca(BUFSIZ);
+		char *message;
+		int rv;
 
 		va_start(ap, fmt);
-		/*
-		 * fill in the message.  If the buffer is too small, allocate
-		 * one that is large enough and fill it in.
-		 */
-		if ((size = vsnprintf(message, BUFSIZ, fmt, ap)) >= BUFSIZ)
-			if ((message = alloca(size)) != NULL)
-				vsnprintf(message, size, fmt, ap);
+		rv = vasprintf(&message, fmt, ap);
 		va_end(ap);
 
-		papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND,
-					"detailed-status-message", message);
+		if (rv >= 0) {
+			papiAttributeListAddString(&svc->attributes,
+			    PAPI_ATTR_APPEND, "detailed-status-message",
+			    message);
+			free(message);
+		}
 	}
 }