[PATCH] pam_winbind: Avoid a use of sprintf

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Mar 31 12:43:02 UTC 2016


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From d2447ee226e2f0a24c34dcce0f78b261f0cccbf0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 31 Mar 2016 14:41:07 +0200
Subject: [PATCH] pam_winbind: Avoid a use of sprintf

pam_winbind depends on talloc, which depends on libreplace, so we have asprintf
available.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 nsswitch/pam_winbind.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c
index b2e1778..42c4f8e 100644
--- a/nsswitch/pam_winbind.c
+++ b/nsswitch/pam_winbind.c
@@ -191,17 +191,17 @@ static void _pam_log_int(const pam_handle_t *pamh,
 {
 	char *format2 = NULL;
 	const char *service;
+	int ret;
 
 	pam_get_item(pamh, PAM_SERVICE, (const void **) &service);
 
-	format2 = (char *)malloc(strlen(MODULE_NAME)+strlen(format)+strlen(service)+5);
-	if (format2 == NULL) {
+	ret = asprintf(&format2, "%s(%s): %s", MODULE_NAME, service, format);
+	if (ret == -1) {
 		/* what else todo ? */
 		vsyslog(err, format, args);
 		return;
 	}
 
-	sprintf(format2, "%s(%s): %s", MODULE_NAME, service, format);
 	vsyslog(err, format2, args);
 	SAFE_FREE(format2);
 }
-- 
1.7.9.5



More information about the samba-technical mailing list