[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r104398: avoid a sign-extension bug i
From: |
Jim Meyering |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r104398: avoid a sign-extension bug in crypto_hash_function |
Date: |
Sat, 28 May 2011 14:19:08 +0200 |
User-agent: |
Bazaar (2.3.1) |
------------------------------------------------------------
revno: 104398
committer: Jim Meyering <address@hidden>
branch nick: trunk
timestamp: Sat 2011-05-28 14:19:08 +0200
message:
avoid a sign-extension bug in crypto_hash_function
* fns.c (to_uchar): Define.
(crypto_hash_function): Use it to convert some newly-signed
variables to unsigned, to avoid sign-extension bugs. For example,
without this change, (md5 "truc") would evaluate to
45723a2aff78ff4fff7fff1114760e62 rather than the expected
45723a2af3788c4ff17f8d1114760e62. Reported by Antoine Levitt in
http://thread.gmane.org/gmane.emacs.devel/139824
modified:
src/ChangeLog
src/fns.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2011-05-27 19:58:54 +0000
+++ b/src/ChangeLog 2011-05-28 12:19:08 +0000
@@ -1,3 +1,14 @@
+2011-05-28 Jim Meyering <address@hidden>
+
+ avoid a sign-extension bug in crypto_hash_function
+ * fns.c (to_uchar): Define.
+ (crypto_hash_function): Use it to convert some newly-signed
+ variables to unsigned, to avoid sign-extension bugs. For example,
+ without this change, (md5 "truc") would evaluate to
+ 45723a2aff78ff4fff7fff1114760e62 rather than the expected
+ 45723a2af3788c4ff17f8d1114760e62. Reported by Antoine Levitt in
+ http://thread.gmane.org/gmane.emacs.devel/139824
+
2011-05-27 Paul Eggert <address@hidden>
Integer overflow fixes.
=== modified file 'src/fns.c'
--- a/src/fns.c 2011-05-27 19:37:32 +0000
+++ b/src/fns.c 2011-05-28 12:19:08 +0000
@@ -4520,6 +4520,11 @@
#include "md5.h"
#include "sha1.h"
+/* Convert a possibly-signed character to an unsigned character. This is
+ a bit safer than casting to unsigned char, since it catches some type
+ errors that the cast doesn't. */
+static inline unsigned char to_uchar (char ch) { return ch; }
+
/* TYPE: 0 for md5, 1 for sha1. */
static Lisp_Object
@@ -4717,7 +4722,7 @@
{
char value[33];
for (i = 0; i < 16; i++)
- sprintf (&value[2 * i], "%02x", digest[i]);
+ sprintf (&value[2 * i], "%02x", to_uchar (digest[i]));
res = make_string (value, 32);
}
else
@@ -4735,7 +4740,7 @@
{
char value[41];
for (i = 0; i < 20; i++)
- sprintf (&value[2 * i], "%02x", digest[i]);
+ sprintf (&value[2 * i], "%02x", to_uchar (digest[i]));
res = make_string (value, 40);
}
else
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r104398: avoid a sign-extension bug in crypto_hash_function,
Jim Meyering <=