svn commit: trunk/uClibc: libc/inet libcrypt

vda at uclibc.org vda at uclibc.org
Mon Jul 30 16:55:05 UTC 2007


Author: vda
Date: 2007-07-30 09:55:05 -0700 (Mon, 30 Jul 2007)
New Revision: 19346

Log:
make getnetent.c, md5.c use __uc_malloc



Modified:
   trunk/uClibc/libc/inet/getnetent.c
   trunk/uClibc/libcrypt/md5.c


Changeset:
Modified: trunk/uClibc/libc/inet/getnetent.c
===================================================================
--- trunk/uClibc/libc/inet/getnetent.c	2007-07-30 16:54:31 UTC (rev 19345)
+++ trunk/uClibc/libc/inet/getnetent.c	2007-07-30 16:55:05 UTC (rev 19346)
@@ -19,6 +19,7 @@
 #include <features.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <malloc.h>
 #include <netdb.h>
 #include <arpa/inet.h>
 
@@ -32,14 +33,9 @@
 #include <bits/uClibc_mutex.h>
 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
 
+static const char NETDB[] = _PATH_NETWORKS;
 
-
-#define	MAXALIASES	35
-static const char NETDB[] = _PATH_NETWORKS;
 static FILE *netf = NULL;
-static char *line = NULL;
-static struct netent net;
-static char *net_aliases[MAXALIASES];
 
 int _net_stayopen attribute_hidden;
 
@@ -83,6 +79,22 @@
     return ((char *)0);
 }
 
+#define	MAXALIASES	35
+static struct {
+	char *line;
+	struct netent net;
+	char *net_aliases[MAXALIASES];
+} *sp;
+#define line        (sp->line)
+#define net         (sp->net)
+#define net_aliases (sp->net_aliases)
+#define INIT_SP() { \
+    if (!sp) { \
+	sp = __uc_malloc(sizeof(*sp)); \
+	line = NULL; \
+    } \
+}
+
 libc_hidden_proto(getnetent)
 struct netent *getnetent(void)
 {
@@ -90,6 +102,8 @@
     register char *cp, **q;
     struct netent *rv = NULL;
 
+    INIT_SP();
+
     __UCLIBC_MUTEX_LOCK(mylock);
     if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL) {
 	goto DONE;

Modified: trunk/uClibc/libcrypt/md5.c
===================================================================
--- trunk/uClibc/libcrypt/md5.c	2007-07-30 16:54:31 UTC (rev 19345)
+++ trunk/uClibc/libcrypt/md5.c	2007-07-30 16:55:05 UTC (rev 19346)
@@ -76,6 +76,7 @@
 #include <sys/types.h>
 #include <string.h>
 #include <unistd.h>
+#include <malloc.h>
 #include <stdio.h>
 #include <crypt.h>
 #include <sys/cdefs.h>
@@ -95,7 +96,10 @@
 static void __md5_Transform __P((u_int32_t [4], const unsigned char [64]));
 
 
-static const unsigned char __md5__magic[] = "$1$";	/* This string is magic for this algorithm.  Having 
+#define MD5_MAGIC_STR "$1$"
+#define MD5_MAGIC_LEN (sizeof(MD5_MAGIC_STR) - 1)
+static const unsigned char __md5__magic[] = MD5_MAGIC_STR;
+						/* This string is magic for this algorithm.  Having 
 						   it this way, we can get better later on */
 static const unsigned char __md5_itoa64[] =		/* 0 ... 63 => ascii - 64 */
 	"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -534,21 +538,24 @@
 char *__md5_crypt(const unsigned char *pw, const unsigned char *salt)
 {
 	/* Static stuff */
-	static const unsigned char *sp, *ep;
-	static char passwd[120], *p;
+	static char *passwd;
 
+	const unsigned char *sp, *ep;
+	char *p;
 	unsigned char	final[17];	/* final[16] exists only to aid in looping */
-	int sl,pl,i,__md5__magic_len,pw_len;
+	int sl,pl,i,pw_len;
 	struct MD5Context ctx,ctx1;
 	unsigned long l;
 
+	if (!passwd)
+		passwd = __uc_malloc(120);
+
 	/* Refine the Salt first */
 	sp = salt;
 
 	/* If it starts with the magic string, then skip that */
-	__md5__magic_len = strlen(__md5__magic);
-	if(!strncmp(sp,__md5__magic,__md5__magic_len))
-		sp += __md5__magic_len;
+	if(!strncmp(sp,__md5__magic,MD5_MAGIC_LEN))
+		sp += MD5_MAGIC_LEN;
 
 	/* It stops at the first '$', max 8 chars */
 	for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++)
@@ -564,7 +571,7 @@
 	__md5_Update(&ctx,pw,pw_len);
 
 	/* Then our magic string */
-	__md5_Update(&ctx,__md5__magic,__md5__magic_len);
+	__md5_Update(&ctx,__md5__magic,MD5_MAGIC_LEN);
 
 	/* Then the raw salt */
 	__md5_Update(&ctx,sp,sl);




More information about the uClibc-cvs mailing list