Control: tags -1 + patch

Jérémy Bobbio:
> The attached patch changes the `mangle()` function accordingly.

For real, this time.

-- 
Lunar                                .''`. 
[email protected]                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
From 503fb7de2fe26eaf126ce7698931434517a3d418 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Bobbio?= <[email protected]>
Date: Tue, 23 Sep 2014 16:56:46 +0000
Subject: [PATCH] Provide a stable output for email address accross runs

Email adresses were previously mangled randomly. This prevented two runs of
discount from providing the same output. This is problematic for software
using discount and compare its output to some reference, or for software which
wants to generate documentation in a reproducible manner.

We can assume that the current code is trying to defeat an email address
scraper that supports one encoding but not the other. Simply alternating
between the two encodings would accomplish the same effect.

We thus change the behaviour of the `mangle()` function to alternate the
encoding based on the position in the string instead of randomly. As there is
no other users of the `COINTOSS()` macro, we can remove its definition from the
configure script.
---
 configure.sh | 8 --------
 generate.c   | 2 +-
 2 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/configure.sh b/configure.sh
index 44c8986..8d009f4 100755
--- a/configure.sh
+++ b/configure.sh
@@ -105,14 +105,6 @@ else
     AC_FAIL "$TARGET requires bzero or memset"
 fi
 
-if AC_CHECK_FUNCS random; then
-    AC_DEFINE 'COINTOSS()' '(random()&1)'
-elif AC_CHECK_FUNCS rand; then
-    AC_DEFINE 'COINTOSS()' '(rand()&1)'
-else
-    AC_DEFINE 'COINTOSS()' '1'
-fi
-
 if AC_CHECK_FUNCS strcasecmp; then
     :
 elif AC_CHECK_FUNCS stricmp; then
diff --git a/generate.c b/generate.c
index 7180a1e..0935f78 100644
--- a/generate.c
+++ b/generate.c
@@ -775,7 +775,7 @@ mangle(char *s, int len, MMIOT *f)
 {
     while ( len-- > 0 ) {
 	Qstring("&#", f);
-	Qprintf(f, COINTOSS() ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
+	Qprintf(f, (len % 2 == 0) ? "x%02x;" : "%02d;", *((unsigned char*)(s++)) );
     }
 }
 
-- 
2.1.0

Attachment: signature.asc
Description: Digital signature

Reply via email to