diff options
| author | Toomas Soome <tsoome@me.com> | 2020-01-04 20:29:28 +0200 |
|---|---|---|
| committer | Toomas Soome <tsoome@me.com> | 2020-01-14 19:08:02 +0200 |
| commit | b666b5bebdde1067e2d0f2b91fd28a5243311a1a (patch) | |
| tree | 76410b1c0abbcf41a68a84870e08a250e9492a76 /usr/src/lib/print | |
| parent | dd2ed563fd8f7f157d5cd583cae81fef585c2ffc (diff) | |
| download | illumos-joyent-b666b5bebdde1067e2d0f2b91fd28a5243311a1a.tar.gz | |
12165 lp: argument to 'alloca' may be too large
Reviewed by: Matthias Scheler <mscheler@tintri.com>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/print')
| -rw-r--r-- | usr/src/lib/print/libpapi-dynamic/common/service.c | 27 | ||||
| -rw-r--r-- | usr/src/lib/print/libpapi-ipp/common/service.c | 25 | ||||
| -rw-r--r-- | usr/src/lib/print/libpapi-lpd/common/service.c | 23 |
3 files changed, 28 insertions, 47 deletions
diff --git a/usr/src/lib/print/libpapi-dynamic/common/service.c b/usr/src/lib/print/libpapi-dynamic/common/service.c index 55f1732a65..fb1316f559 100644 --- a/usr/src/lib/print/libpapi-dynamic/common/service.c +++ b/usr/src/lib/print/libpapi-dynamic/common/service.c @@ -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 @@ detailed_error(service_t *svc, char *fmt, ...) { 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); + } } } diff --git a/usr/src/lib/print/libpapi-ipp/common/service.c b/usr/src/lib/print/libpapi-ipp/common/service.c index e5531f1422..eac12c17f3 100644 --- a/usr/src/lib/print/libpapi-ipp/common/service.c +++ b/usr/src/lib/print/libpapi-ipp/common/service.c @@ -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 @@ detailed_error(service_t *svc, char *fmt, ...) { 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); + } } } diff --git a/usr/src/lib/print/libpapi-lpd/common/service.c b/usr/src/lib/print/libpapi-lpd/common/service.c index c39ea0cbb5..7d5eccf1d9 100644 --- a/usr/src/lib/print/libpapi-lpd/common/service.c +++ b/usr/src/lib/print/libpapi-lpd/common/service.c @@ -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 @@ detailed_error(service_t *svc, char *fmt, ...) { 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); + } } } |
