File: 0005-Fix-uninitialized-variable-error.patch

package info (click to toggle)
rc 1.7.4%2B97.gceb59bb-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 800 kB
  • sloc: ansic: 7,965; yacc: 136; sh: 133; makefile: 49; perl: 25; sed: 5
file content (45 lines) | stat: -rw-r--r-- 1,053 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
From: Dmitry Bogatov <KAction@debian.org>
Date: Mon, 12 Aug 2019 23:26:46 +0000
Subject: Fix uninitialized variable error

If stat(2) in `rc_access', statbuf is left uninitialized, but still used in
conditional.

Detected with valgrind.

Updated to avoid crash in tab completion,
details in https://bugs.debian.org/1004645.

Forwarded: https://github.com/rakitzis/rc/pull/56
---
 edit-readline.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/edit-readline.c b/edit-readline.c
index 47c8db5..8a9d0fa 100644
--- a/edit-readline.c
+++ b/edit-readline.c
@@ -116,7 +116,14 @@ static char *entry(char *dname, char *name, char *subdirs,
 		efree(full);
 		return maybe_quote(dir_join(subdirs, name));
 	}
+	
+	if (stat(full, &st) != 0) {
+		goto null;
+	}
+
 	efree(full);
+	full = NULL;
+
 	if (S_ISDIR(st.st_mode)) {
 		char *dir_ret = ealloc(strlen(name) + 5);
 		char *r;
@@ -128,6 +135,8 @@ static char *entry(char *dname, char *name, char *subdirs,
 		efree(dir_ret);
 		return maybe_quote(r);
 	}
+null:
+	efree(full);
 	return NULL;
 }