File: 0010-nextpass-doesn-t-need-to-allocate.patch

package info (click to toggle)
rarcrack 0.2%2B20240214~413ea3a-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 376 kB
  • sloc: ansic: 359; sh: 70; makefile: 26
file content (52 lines) | stat: -rw-r--r-- 1,275 bytes parent folder | download | duplicates (2)
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
From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Mon, 25 Nov 2024 21:50:30 +0100
Subject: nextpass() doesn't need to allocate

---
 rarcrack.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/rarcrack.c b/rarcrack.c
index 4bc3d4c..0be9f59 100644
--- a/rarcrack.c
+++ b/rarcrack.c
@@ -210,14 +210,12 @@ void nextpass2(char *p, unsigned int n) {
     }
 }
 
-char *nextpass() {
+void nextpass(char ok[static PWD_LEN+1]) {
     //IMPORTANT: the returned string must be freed
-    char *ok = malloc(sizeof(char)*(PWD_LEN+1));
     xmlMutexLock(pwdMutex);
     strcpy(ok, password);
     nextpass2((char*) &password, curr_len - 1);
     xmlMutexUnlock(pwdMutex);
-    return ok;
 }
 
 void *status_thread() {
@@ -242,13 +240,13 @@ void *status_thread() {
 }
 
 void *crack_thread() {
-    char *current;
+    char current[PWD_LEN+1];
     char *ret = NULL;
     size_t retlen = 0;
     FILE *Pipe;
     int fds[2];
     while (1) {
-        current = nextpass();
+        nextpass(current);
         (void) -pipe2(fds, O_CLOEXEC);
         if (!vfork()) {
             dup2(fds[1], 1);
@@ -281,7 +279,6 @@ void *crack_thread() {
         }
 
         xmlMutexUnlock(finishedMutex);
-        free(current);
     }
     free(ret);
 }