[Pkg-wmaker-commits] [wmbiff] 36/38: fix memfrob * bug (memfrob makes *'s zero, so password length must be tracked separately

Doug Torrance dtorrance-guest at moszumanska.debian.org
Thu Aug 20 03:03:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to tag wmbiff_0_4_16
in repository wmbiff.

commit 45a06240dc099598de8a43b32b59cb0c5f0841f5
Author: bluehal <bluehal>
Date:   Mon Jul 7 08:43:01 2003 +0000

    fix memfrob * bug (memfrob makes *'s zero, so password length must be tracked separately
---
 wmbiff/Client.h      |  5 +++--
 wmbiff/Imap4Client.c | 15 ++++++++-------
 wmbiff/passwordMgr.c | 19 +++++++++++++------
 wmbiff/test_wmbiff.c | 29 ++++++++++++++++++++++++++---
 4 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/wmbiff/Client.h b/wmbiff/Client.h
index 216cffb..0e8cec8 100644
--- a/wmbiff/Client.h
+++ b/wmbiff/Client.h
@@ -1,11 +1,11 @@
-/* $Id: Client.h,v 1.34 2003/06/08 07:01:08 bluehal Exp $ */
+/* $Id: Client.h,v 1.35 2003/07/07 08:43:01 bluehal Exp $ */
 /* Author : Scott Holden ( scotth at thezone.net )
    Modified : Yong-iL Joh ( tolkien at mizi.com )
    Modified : Jorge Garc�a ( Jorge.Garcia at uv.es )
  *
  * Email Checker Pop3/Imap4/Licq/Gicu/mbox/maildir/finger
  *
- * Last Updated : $Date: 2003/06/08 07:01:08 $
+ * Last Updated : $Date: 2003/07/07 08:43:01 $
  *
  */
 
@@ -74,6 +74,7 @@ typedef struct _mbox_t {
 			unsigned int dossl:1;	/* use tls. */
 			/* prompt the user if we can't login / password is empty */
 			unsigned int interactive_password:1;
+			unsigned char password_len;
 		} pop_imap;
 	} u;
 
diff --git a/wmbiff/Imap4Client.c b/wmbiff/Imap4Client.c
index 0c62df4..4e99b46 100644
--- a/wmbiff/Imap4Client.c
+++ b/wmbiff/Imap4Client.c
@@ -37,8 +37,8 @@ extern int Relax;
 #define IMAP_DM(pc, lvl, args...) DM(pc, lvl, "imap4: " args)
 
 #ifdef HAVE_MEMFROB
-#define DEFROB(x) memfrob(x, strlen(x))
-#define ENFROB(x) memfrob(x, strlen(x))
+#define DEFROB(x) memfrob(x, x ## _len)
+#define ENFROB(x) memfrob(x, x ## _len)
 #else
 #define DEFROB(x)
 #define ENFROB(x)
@@ -183,7 +183,8 @@ FILE *imap_open(Pop3 pc)
 	if (sd == -1) {
 		if (complained_already == 0) {
 			IMAP_DM(pc, DEBUG_ERROR, "Couldn't connect to %s:%d: %s\n",
-					PCU.serverName, PCU.serverPort, strerror(errno));
+					PCU.serverName, PCU.serverPort,
+					errno ? strerror(errno) : "");
 			complained_already = 1;
 		}
 		if (errno == ETIMEDOUT) {
@@ -528,12 +529,11 @@ int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
 		return -1;
 	}
 
+	PCU.password_len = strlen(PCU.password);
 	if (PCU.password[0] == '\0') {
 		PCU.interactive_password = 1;
 	} else {
-#ifdef HAVE_MEMFROB
-		memfrob(PCU.password, strlen(PCU.password));
-#endif
+		ENFROB(PCU.password);
 	}
 
 	// grab_authList(unaliased_str + matchedchars, PCU.authList);
@@ -542,7 +542,7 @@ int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
 
 	IMAP_DM(pc, DEBUG_INFO, "userName= '%s'\n", PCU.userName);
 	IMAP_DM(pc, DEBUG_INFO, "password is %d characters long\n",
-			(int) strlen(PCU.password));
+			(int) PCU.password_len);
 	IMAP_DM(pc, DEBUG_INFO, "serverName= '%s'\n", PCU.serverName);
 	IMAP_DM(pc, DEBUG_INFO, "serverPath= '%s'\n", pc->path);
 	IMAP_DM(pc, DEBUG_INFO, "serverPort= '%d'\n", PCU.serverPort);
@@ -678,6 +678,7 @@ static void ask_user_for_password( /*@notnull@ */ Pop3 pc, int bFlushCache)
 				passwordFor(PCU.userName, PCU.serverName, pc, bFlushCache);
 			if (password != NULL) {
 				strcpy(PCU.password, password);
+				PCU.password_len = strlen(password);
 				free(password);
 				ENFROB(PCU.password);
 			}
diff --git a/wmbiff/passwordMgr.c b/wmbiff/passwordMgr.c
index 42ab405..41f3668 100644
--- a/wmbiff/passwordMgr.c
+++ b/wmbiff/passwordMgr.c
@@ -38,11 +38,20 @@
 #include <sys/stat.h>
 #include "assert.h"
 
+#ifdef HAVE_MEMFROB
+#define DEFROB(x) memfrob(x, x ## _len)
+#define ENFROB(x) memfrob(x, x ## _len)
+#else
+#define DEFROB(x)
+#define ENFROB(x)
+#endif
+
 typedef struct password_binding_struct {
 	struct password_binding_struct *next;
 	char user[32];
 	char server[255];
 	char password[32];			/* may be frobnicated */
+	unsigned char password_len;	/* frobnicated *'s are nulls */
 } *password_binding;
 
 static password_binding pass_list = NULL;
@@ -101,9 +110,8 @@ char *passwordFor(const char *username,
 		if (p->password[0] != '\0') {
 			if (bFlushCache == 0) {
 				char *ret = strdup(p->password);
-#ifdef HAVE_MEMFROB
-				memfrob(ret, strlen(ret));
-#endif
+				unsigned short ret_len = p->password_len;
+				DEFROB(ret);
 				return (ret);
 			}
 			/* else fall through, overwrite */
@@ -154,9 +162,8 @@ char *passwordFor(const char *username,
 			strncpy(p->password, password_ptr, 31);
 			p->password[31] = '\0';	/* force a null termination */
 			// caller is responsible for freeing plaintext version free(password_ptr);
-#ifdef HAVE_MEMFROB
-			memfrob(p->password, strlen(p->password));
-#endif
+			p->password_len = strlen(p->password);
+			ENFROB(p->password);
 			p->next = pass_list;
 			pass_list = p;
 			if (strlen(password_ptr) > 31) {
diff --git a/wmbiff/test_wmbiff.c b/wmbiff/test_wmbiff.c
index a279e9a..8430690 100644
--- a/wmbiff/test_wmbiff.c
+++ b/wmbiff/test_wmbiff.c
@@ -9,8 +9,8 @@
 #endif
 
 #ifdef HAVE_MEMFROB
-#define DEFROB(x) memfrob(x, strlen(x))
-#define ENFROB(x) memfrob(x, strlen(x))
+#define DEFROB(x) memfrob(x, x ## _len)
+#define ENFROB(x) memfrob(x, x ## _len)
 #else
 #define DEFROB(x)
 #define ENFROB(x)
@@ -55,7 +55,7 @@ int test_backtickExpand(void) {
 
 #define CKSTRING(x,shouldbe) if(strcmp(x,shouldbe)) { \
 printf("Failed: expected '" #shouldbe "' but got '%s'\n", x); \
- return 1; }
+ return 1; } else { printf("good: '" shouldbe "' == '%s'\n", x); } 
 
 /* return 1 if fail, 0 if success */
 int test_passwordMgr(void) {
@@ -152,6 +152,14 @@ int test_passwordMgr(void) {
 		return(1);
 	}
 	printf("SUCCESS: expected '' got '%s'\n", b);
+
+	m.askpass = "echo \"rt*m\"; #";
+	b = passwordFor("faq", "faq", &m, 0);
+	if (strcmp(b, "rt*m") != 0) {
+		printf("FAILURE: expected '' got '%s'\n", b);
+		return(1);
+	}
+	printf("SUCCESS: expected 'rt*m' got '%s'\n", b);
     return(0);
 }
 
@@ -189,6 +197,21 @@ int test_imap4creator(void) {
     CKSTRING(m.u.pop_imap.serverName, "bar");
     CKINT(m.u.pop_imap.serverPort, 143);
 
+    if(imap4Create(&m, "imap:star *as* star/\"space box\"")) {
+        return 1;
+    }
+    printf("mmm %s", (m.u.pop_imap.password));
+    DEFROB(m.u.pop_imap.password);
+    CKSTRING(m.u.pop_imap.password, "*as*");
+    CKINT(m.u.pop_imap.serverPort, 143);
+    if(imap4Create(&m, "imap:user:*as*@bar/blah")) {
+        return 1;
+    }
+    
+    DEFROB(m.u.pop_imap.password);
+    CKSTRING(m.u.pop_imap.password, "*as*");
+    CKINT(m.u.pop_imap.serverPort, 143);
+
     if(imap4Create(&m, "imap:user pass bar/\"space box\" 12")) {
         return 1;
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbiff.git



More information about the Pkg-wmaker-commits mailing list