[dovecot-cvs] dovecot/src/auth passdb-pam.c,1.35,1.36

cras at dovecot.org cras at dovecot.org
Sun Feb 5 09:24:39 EET 2006


Update of /var/lib/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv10421

Modified Files:
	passdb-pam.c 
Log Message:
If error message from PAM was over ~500 bytes, we crashed. Probably never
happened. Also use PIPE_BUF instead of hardcoded 512 bytes.



Index: passdb-pam.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/auth/passdb-pam.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- passdb-pam.c	22 Jan 2006 10:27:25 -0000	1.35
+++ passdb-pam.c	5 Feb 2006 07:24:37 -0000	1.36
@@ -237,7 +237,7 @@
 	enum passdb_result result;
 	int ret, status, status2;
 	const char *str;
-	char buf_data[512];
+	size_t size;
 	buffer_t *buf;
 
 	conv.conv = pam_userpass_conv;
@@ -269,16 +269,16 @@
 		}
 	}
 
-	buf = buffer_create_data(pool_datastack_create(),
-				 buf_data, sizeof(buf_data));
+	buf = buffer_create_dynamic(pool_datastack_create(), 512);
 	buffer_append(buf, &result, sizeof(result));
 
-	if (str != NULL) {
-		/* may truncate the error. tough luck. */
+	if (str != NULL) 
 		buffer_append(buf, str, strlen(str));
-	}
 
-	if ((ret = write(fd, buf_data, buf->used)) != (int)buf->used) {
+	/* Don't send larger writes than what would block. truncated error
+	   message isn't that bad.. */
+        size = I_MIN(buf->used, PIPE_BUF);
+	if ((ret = write(fd, buf->data, size)) != (int)size) {
 		if (ret < 0)
 			i_error("write() failed: %m");
 		else {
@@ -293,11 +293,11 @@
 	struct pam_auth_request *request = context;
 	struct auth_request *auth_request = request->request;
 	enum passdb_result result;
-	char buf[513];
+	char buf[PIPE_BUF + 1];
 	ssize_t ret;
 
-	/* POSIX guarantees that writing 512 bytes or less to pipes is atomic.
-	   We rely on that. */
+	/* POSIX guarantees that writing PIPE_BUF bytes or less to pipes is
+	   atomic. We rely on that. */
 	ret = read(request->fd, buf, sizeof(buf)-1);
 	if (ret < 0) {
 		auth_request_log_error(auth_request, "pam",



More information about the dovecot-cvs mailing list