summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support/nettle/nettle-3.4.1/0001-nettle-pbkdf2.c-change-the-initialization-for-salt.patch
blob: 713823e294ba24fb778b7a1c02a66674a372604f (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
From 7510ee2877368464ecce7de515ce056e08c75245 Mon Sep 17 00:00:00 2001
From: Mingli Yu <Mingli.Yu@windriver.com>
Date: Fri, 12 Apr 2019 10:30:14 +0800
Subject: [PATCH] nettle-pbkdf2.c: change the initialization for salt

use malloc and strncpy altogether to replace
strdup for salt initialization to fix below
Segmentation fault:
 # echo -n passwd| nettle-pbkdf2 -i 1 -l 16 salt
 [65534.886509] nettle-pbkdf2[708]: segfault at 1f594260 ip 00007f3332256998 sp 00007fff60d44410 error 4 in libnettle.so.6.5[7f3332244000+1d00]
 [65534.887525] Code: e8 6d db fe ff 44 01 6d 68 48 83 c4 08 5b 5d 41 5c 41 5d 41 5e 41 5f c3 66 2e 0f 1f 84 00 00 00 00 00 49 89 dc e9 68 ff f
 Segmentation fault

Upstream-Status: Submitted[http://lists.lysator.liu.se/pipermail/nettle-bugs/2019/007467.html]

Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>
---
 tools/nettle-pbkdf2.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/nettle-pbkdf2.c b/tools/nettle-pbkdf2.c
index 1f0a301..000acd3 100644
--- a/tools/nettle-pbkdf2.c
+++ b/tools/nettle-pbkdf2.c
@@ -141,7 +141,10 @@ main (int argc, char **argv)
       return EXIT_FAILURE;
     }
 
-  salt = strdup (argv[0]);
+  salt = malloc (strlen(argv[0]) + 1);
+  if (! salt)
+     die ("Failed to allocate memory for salt\n");
+  strncpy(salt, argv[0], sizeof(salt) - 1);
   salt_length = strlen(argv[0]);
   
   if (hex_salt)
-- 
2.7.4