Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/openpam/dist/lib don't allocate variable arrays...



details:   https://anonhg.NetBSD.org/src/rev/0127fce6fde2
branches:  trunk
changeset: 772283:0127fce6fde2
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Dec 27 20:29:08 2011 +0000

description:
don't allocate variable arrays on the stack for SSP (from joerg)

diffstat:

 external/bsd/openpam/dist/lib/pam_start.c |  26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diffs (66 lines):

diff -r a4fe2b9d9b5d -r 0127fce6fde2 external/bsd/openpam/dist/lib/pam_start.c
--- a/external/bsd/openpam/dist/lib/pam_start.c Tue Dec 27 19:36:10 2011 +0000
+++ b/external/bsd/openpam/dist/lib/pam_start.c Tue Dec 27 20:29:08 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_start.c,v 1.2 2011/12/25 22:27:56 christos Exp $   */
+/*     $NetBSD: pam_start.c,v 1.3 2011/12/27 20:29:08 christos Exp $   */
 
 /*-
  * Copyright (c) 2002-2003 Networks Associates Technology, Inc.
@@ -50,11 +50,6 @@
 #include "openpam_impl.h"
 #include "openpam_strlcpy.h"
 
-#ifdef _SC_HOST_NAME_MAX
-#define HOST_NAME_MAX sysconf(_SC_HOST_NAME_MAX)
-#else
-#define HOST_NAME_MAX 1024
-#endif
 
 /*
  * XSSO 4.2.1
@@ -69,17 +64,28 @@
        const struct pam_conv *pam_conv,
        pam_handle_t **pamh)
 {
-       char hostname[HOST_NAME_MAX + 1];
+       char *hostname = NULL;
        struct pam_handle *ph;
        int r;
+       size_t hostname_size;
+       long h;
+
+#ifdef _SC_HOST_NAME_MAX
+       h = sysconf(_SC_HOST_NAME_MAX);
+#else
+       h = -1;
+#endif
+       hostname_size = (h < 10 ? 1024 : h) + 1;
 
        ENTER();
        if ((ph = calloc((size_t)1, sizeof *ph)) == NULL)
                RETURNC(PAM_BUF_ERR);
        if ((r = pam_set_item(ph, PAM_SERVICE, service)) != PAM_SUCCESS)
                goto fail;
-       if (gethostname(hostname, sizeof hostname) != 0)
-               strlcpy(hostname, "localhost", sizeof hostname);
+       if ((hostname = malloc(hostname_size)) == NULL)
+               goto fail;
+       if (gethostname(hostname, hostname_size) != 0)
+               strlcpy(hostname, "localhost", hostname_size);
        if ((r = pam_set_item(ph, PAM_HOST, hostname)) != PAM_SUCCESS)
                goto fail;
        if ((r = pam_set_item(ph, PAM_USER, user)) != PAM_SUCCESS)
@@ -88,10 +94,12 @@
                goto fail;
        if ((r = openpam_configure(ph, service)) != PAM_SUCCESS)
                goto fail;
+       free(hostname);
        *pamh = ph;
        openpam_log(PAM_LOG_DEBUG, "pam_start(\"%s\") succeeded", service);
        RETURNC(PAM_SUCCESS);
 fail:
+       free(hostname);
        pam_end(ph, r);
        RETURNC(r);
        /*NOTREACHED*/



Home | Main Index | Thread Index | Old Index