aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/pseudo/files/0003-pseudo_client-Simplify-pseudo_client_ignore_path_chr.patch
blob: a657a27f285a1ff2e016ad3ff400e1aceaaeb7f0 (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
From a1d61d68777373a50ae23b9dd83b428abe2f748d Mon Sep 17 00:00:00 2001
From: Peter Kjellerstedt <pkj@axis.com>
Date: Sat, 21 Nov 2020 17:30:33 +0100
Subject: [PATCH] pseudo_client: Simplify pseudo_client_ignore_path_chroot()

This also plugs a memory leak by making sure env is freed.

Change-Id: Ia8635fd2c6b1e85919e4743713a85e0b52c28fac
---
 pseudo_client.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/pseudo_client.c b/pseudo_client.c
index a8bc3dc..7dc0345 100644
--- a/pseudo_client.c
+++ b/pseudo_client.c
@@ -1538,23 +1538,22 @@ int pseudo_client_ignore_path_chroot(const char *path, int ignore_chroot) {
 	if (!env)
 		return 0;
 
+	int ret = 0;
 	char *p = env;
-	while (*p) {
+	while (p) {
 		char *next = strchr(p, ',');
-		if (!next)
-			next = strchr(p, '\0');
-		if ((next - p) && !strncmp(path, p, next - p)) {
- 			pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "ignoring path: '%s'\n", path);
-			return 1;
-		}
-		if (next && *next != '\0')
-			p = next+1;
-		else
+		if (next)
+			*next++ = '\0';
+		if (*p && !strncmp(path, p, strlen(p))) {
+			pseudo_debug(PDBGF_PATH | PDBGF_VERBOSE, "ignoring path: '%s'\n", path);
+			ret = 1;
 			break;
+		}
+		p = next;
 	}
 	free(env);
 
-	return 0;
+	return ret;
 }
 
 int pseudo_client_ignore_path(const char *path) {