Source-Changes-HG archive

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

[src/trunk]: src/lib/libpam - reverse the order of printf formatting to make ...



details:   https://anonhg.NetBSD.org/src/rev/52f223689047
branches:  trunk
changeset: 772297:52f223689047
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Dec 28 14:52:56 2011 +0000

description:
- reverse the order of printf formatting to make it easier for compilers to
  check printf arguments
- add compiler checking for printf formats and fix broken ones.
>From joerg@

diffstat:

 lib/libpam/libpam/pam_debug_log.c                      |  38 +++++++++--------
 lib/libpam/libpam/security/pam_mod_misc.h              |   4 +-
 lib/libpam/modules/pam_login_access/pam_login_access.c |   8 +-
 3 files changed, 26 insertions(+), 24 deletions(-)

diffs (112 lines):

diff -r 4bdbabb6de46 -r 52f223689047 lib/libpam/libpam/pam_debug_log.c
--- a/lib/libpam/libpam/pam_debug_log.c Wed Dec 28 09:29:03 2011 +0000
+++ b/lib/libpam/libpam/pam_debug_log.c Wed Dec 28 14:52:56 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_debug_log.c,v 1.3 2007/03/09 23:44:50 hubertf Exp $        */
+/*     $NetBSD: pam_debug_log.c,v 1.4 2011/12/28 14:52:56 christos Exp $       */
 
 /*-
  * Copyright 2001 Mark R V Murray
@@ -30,7 +30,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/libpam/pam_debug_log.c,v 1.8 2002/04/14 16:44:04 des Exp $");
 #else
-__RCSID("$NetBSD: pam_debug_log.c,v 1.3 2007/03/09 23:44:50 hubertf Exp $");
+__RCSID("$NetBSD: pam_debug_log.c,v 1.4 2011/12/28 14:52:56 christos Exp $");
 #endif
 
 #include <stdarg.h>
@@ -50,22 +50,24 @@
     const char *file, const char *function, const char *format, ...)
 {
        va_list ap;
-       char *fmtbuf;
+       char *msg;
+       int rv;
        const char *modname, *period;
 
-       if (!(flags & PAM_SILENT) && !openpam_get_option(pamh, "no_warn")) {
-               modname = strrchr(file, '/');
-               if (modname == NULL)
-                       modname = file;
-               period = strchr(modname, '.');
-               if (period == NULL)
-                       period = strchr(modname, '\0');
-               va_start(ap, format);
-               asprintf(&fmtbuf, "%.*s: %s: %s\n",
-                   (int)(ssize_t)(period - modname), modname, function,
-                   format);
-               pam_verror(pamh, fmtbuf, ap);
-               free(fmtbuf);
-               va_end(ap);
-       }
+       if ((flags & PAM_SILENT) || openpam_get_option(pamh, "no_warn"))
+               return;
+       modname = strrchr(file, '/');
+       if (modname == NULL)
+               modname = file;
+       period = strchr(modname, '.');
+       if (period == NULL)
+               period = strchr(modname, '\0');
+       va_start(ap, format);
+       rv = vasprintf(&msg, format, ap);
+       va_end(ap);
+       if (rv < 0)
+               return;
+       pam_error(pamh, "%.*s: %s: %s\n", (int)(ssize_t)(period - modname),
+           modname, function, msg);
+       free(msg);
 }
diff -r 4bdbabb6de46 -r 52f223689047 lib/libpam/libpam/security/pam_mod_misc.h
--- a/lib/libpam/libpam/security/pam_mod_misc.h Wed Dec 28 09:29:03 2011 +0000
+++ b/lib/libpam/libpam/security/pam_mod_misc.h Wed Dec 28 14:52:56 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_mod_misc.h,v 1.3 2004/12/12 08:30:26 christos Exp $        */
+/*     $NetBSD: pam_mod_misc.h,v 1.4 2011/12/28 14:52:56 christos Exp $        */
 
 /*-
  * Copyright 1998 Juniper Networks, Inc.
@@ -43,7 +43,7 @@
 
 __BEGIN_DECLS
 void   _pam_verbose_error(pam_handle_t *, int, const char *,
-               const char *, const char *, ...);
+               const char *, const char *, ...) __printflike(5, 6);
 __END_DECLS
 
 #define        PAM_LOG(...) \
diff -r 4bdbabb6de46 -r 52f223689047 lib/libpam/modules/pam_login_access/pam_login_access.c
--- a/lib/libpam/modules/pam_login_access/pam_login_access.c    Wed Dec 28 09:29:03 2011 +0000
+++ b/lib/libpam/modules/pam_login_access/pam_login_access.c    Wed Dec 28 14:52:56 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_login_access.c,v 1.3 2006/11/03 18:03:23 christos Exp $    */
+/*     $NetBSD: pam_login_access.c,v 1.4 2011/12/28 14:52:56 christos Exp $    */
 
 /*-
  * Copyright (c) 2001 Mark R V Murray
@@ -40,7 +40,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_login_access/pam_login_access.c,v 1.11 2004/02/10 10:13:21 des Exp $");
 #else
-__RCSID("$NetBSD: pam_login_access.c,v 1.3 2006/11/03 18:03:23 christos Exp $");
+__RCSID("$NetBSD: pam_login_access.c,v 1.4 2011/12/28 14:52:56 christos Exp $");
 #endif
 
 #define _BSD_SOURCE
@@ -90,14 +90,14 @@
                if (login_access(user, tty) != 0)
                        return (PAM_SUCCESS);
                PAM_VERBOSE_ERROR("%s is not allowed to log in on %s",
-                   user, tty);
+                   (const char *)user, (const char *)tty);
        } else {
                PAM_LOG("Checking login.access for user %s from host %s",
                    (const char *)user, (const char *)rhost);
                if (login_access(user, rhost) != 0)
                        return (PAM_SUCCESS);
                PAM_VERBOSE_ERROR("%s is not allowed to log in from %s",
-                   user, rhost);
+                   (const char *)user, (const char *)rhost);
        }
 
        return (PAM_AUTH_ERR);



Home | Main Index | Thread Index | Old Index