aboutsummaryrefslogtreecommitdiffstats
path: root/main/libasr/0002-Replace-missing-res_randomid-with-the-more-secure-ar.patch
blob: a843125a5a15ccedcc798860f8900b7197747f44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
From fb2c3b37d1022d84506ca0815c7c888c4f08e90c Mon Sep 17 00:00:00 2001
From: xentec <xentec@aix0.eu>
Date: Sat, 11 Feb 2017 14:39:24 +0000
Subject: [PATCH 2/3] Replace missing res_randomid() with the more secure
 arc4random()

---
 configure.ac                    | 2 ++
 openbsd-compat/openbsd-compat.h | 2 ++
 src/res_mkquery.c               | 2 +-
 src/res_send_async.c            | 2 +-
 4 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 10aff04..fa0e896 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,8 @@
 # libasr specific checks.
 #
 
+LIBS="-lcrypto -lbsd $LIBS"
+
 # This ought to be part of the generic compat library, but we don't want to force
 # linking against other libs (-lresolv for instance) in all cases.
 # It has to be improved at some point.
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index c30591c..9be2e0b 100644
--- a/openbsd-compat/includes/compat-stdlib.h
+++ b/openbsd-compat/includes/compat-stdlib.h
@@ -30,3 +30,5 @@
 long long strtonum(const char *nptr, long long minval, long long maxval,
     const char **errstr);
 #endif
+
+unsigned int arc4random(void);
diff --git a/src/res_mkquery.c b/src/res_mkquery.c
index 27ed21e..cce4029 100644
--- a/src/res_mkquery.c
+++ b/src/res_mkquery.c
@@ -57,7 +57,7 @@ res_mkquery(int op, const char *dname, int class, int type,
 	ac = asr_use_resolver(NULL);
 
 	memset(&h, 0, sizeof h);
-	h.id = res_randomid();
+	h.id = arc4random();
 	if (ac->ac_options & RES_RECURSE)
 		h.flags |= RD_MASK;
 	h.qdcount = 1;
diff --git a/src/res_send_async.c b/src/res_send_async.c
index a60aa0d..a0f4704 100644
--- a/src/res_send_async.c
+++ b/src/res_send_async.c
@@ -380,7 +380,7 @@ setup_query(struct asr_query *as, const char *name, const char *dom,
 	as->as.dns.obuflen = 0;
 
 	memset(&h, 0, sizeof h);
-	h.id = res_randomid();
+	h.id = arc4random();
 	if (as->as_ctx->ac_options & RES_RECURSE)
 		h.flags |= RD_MASK;
 	h.qdcount = 1;
-- 
2.11.1