cvs: php4 /ext/session session.c
| From: | Sascha Schumann | Date: | Sat, 19 May 2001 09:58:32 +0000 |
| Subject: | cvs: php4 /ext/session session.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-5838@lists.php.net to get a copy of this message | ||
sas Sat May 19 02:58:32 2001 EDT
Modified files:
/php4/ext/session session.c
Log:
Improve reading from external data source for session id creation.
Improve generating the string representation of the md5 session id.
Index: php4/ext/session/session.c
diff -u php4/ext/session/session.c:1.202 php4/ext/session/session.c:1.203
--- php4/ext/session/session.c:1.202 Sun May 13 00:37:28 2001
+++ php4/ext/session/session.c Sat May 19 02:58:31 2001
@@ -458,6 +458,8 @@
}
}
+static char hexconvtab[] = "0123456789abcdef";
+
static char *_php_create_id(int *newlen PSLS_DC)
{
PHP_MD5_CTX context;
@@ -465,6 +467,8 @@
char buf[256];
struct timeval tv;
int i;
+ int j = 0;
+ unsigned char c;
gettimeofday(&tv, NULL);
PHP_MD5Init(&context);
@@ -477,27 +481,31 @@
fd = VCWD_OPEN((PS(entropy_file), O_RDONLY));
if (fd >= 0) {
- char *p;
+ char buf[2048];
int n;
+ int to_read = PS(entropy_length);
- p = emalloc(PS(entropy_length));
- n = read(fd, p, PS(entropy_length));
- if (n > 0) {
- PHP_MD5Update(&context, p, n);
+ while (to_read > 0) {
+ n = read(fd, buf, MIN(to_read, sizeof(buf)));
+ if (n <= 0) break;
+ PHP_MD5Update(&context, buf, n);
+ to_read -= n;
}
- efree(p);
close(fd);
}
}
PHP_MD5Final(digest, &context);
-
- for (i = 0; i < 16; i++)
- sprintf(buf + (i << 1), "%02x", digest[i]);
- buf[i << 1] = '\0';
+
+ for (i = 0; i < 16; i++) {
+ c = digest[i];
+ buf[j++] = hexconvtab[c >> 4];
+ buf[j++] = hexconvtab[c & 15];
+ }
+ buf[j] = '\0';
if (newlen)
- *newlen = i << 1;
+ *newlen = j;
return estrdup(buf);
}