Commit | Line | Data |
---|---|---|
21b3b755 MW |
1 | From cb9ee701ef46c1819eed4e2a4dc181682bdfc176 Mon Sep 17 00:00:00 2001 |
2 | From: Philip Withnall <pwithnall@endlessos.org> | |
3 | Date: Wed, 10 Feb 2021 21:16:39 +0000 | |
4 | Subject: [PATCH 1/3] gkeyfilesettingsbackend: Fix basename handling when group | |
5 | is unset | |
6 | ||
7 | Fix an effective regression in commit | |
8 | 7781a9cbd2fd0aa84bee0f4eee88470640ff6706, which happens when | |
9 | `convert_path()` is called with a `key` which contains no slashes. In | |
10 | that case, the `key` is entirely the `basename`. | |
11 | ||
12 | Prior to commit 7781a9cb, the code worked through a fluke of `i == -1` | |
13 | cancelling out with the various additions in the `g_memdup()` call, and | |
14 | effectively resulting in `g_strdup (key)`. | |
15 | ||
16 | Spotted by Guido Berhoerster. | |
17 | ||
18 | Signed-off-by: Philip Withnall <pwithnall@endlessos.org> | |
19 | --- | |
20 | gio/gkeyfilesettingsbackend.c | 7 ++++++- | |
21 | 1 file changed, 6 insertions(+), 1 deletion(-) | |
22 | ||
23 | diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c | |
24 | index 25b057672..861c3a661 100644 | |
25 | --- a/gio/gkeyfilesettingsbackend.c | |
26 | +++ b/gio/gkeyfilesettingsbackend.c | |
27 | @@ -185,7 +185,12 @@ convert_path (GKeyfileSettingsBackend *kfsb, | |
28 | } | |
29 | ||
30 | if (basename) | |
31 | - *basename = g_memdup2 (last_slash + 1, key_len - (last_slash - key)); | |
32 | + { | |
33 | + if (last_slash != NULL) | |
34 | + *basename = g_memdup2 (last_slash + 1, key_len - (last_slash - key)); | |
35 | + else | |
36 | + *basename = g_strdup (key); | |
37 | + } | |
38 | ||
39 | return TRUE; | |
40 | } | |
41 | -- | |
42 | 2.30.1 | |
43 |