Skip to contentSkip to conversation

obex: Use GLib helper function to manipulate paths

PATCH In review Bastien Nocera 2 participants 4 messages Nov 9, 2013 – Nov 24, 2017 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 obex: Use GLib helper function to manipulate paths

Instead of trying to do it by hand. This also makes sure that relative paths aren't used by the agent.

---
 obexd/src/manager.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
obexd/src/manager.c +5 -5
index cec8a39..f18896e 100644
@@ -651,14 +651,14 @@ static void agent_reply(DBusPendingCall *call, void *user_data)
 				DBUS_TYPE_STRING, &name,
 				DBUS_TYPE_INVALID)) {
 		/* Splits folder and name */
-		const char *slash = strrchr(name, '/');
+		gboolean is_relative = !g_path_is_absolute(name);
 		DBG("Agent replied with %s", name);
-		if (!slash) {
-			agent->new_name = g_strdup(name);
+		if (is_relative) {
+			agent->new_name = g_path_get_basename(name);
 			agent->new_folder = NULL;
 		} else {
-			agent->new_name = g_strdup(slash + 1);
-			agent->new_folder = g_strndup(name, slash - name);
+			agent->new_name = g_path_get_basename(name);
+			agent->new_folder = g_path_get_dirname(name);
 		}
 	}
 
Signature · 1 line
1.8.4.2
#1 lore raw
Quoted 2 lines · Bastien Nocera

Instead of trying to do it by hand. This also makes sure that relative paths aren't used by the agent.

This is still relevant and applicable.

#2 lore raw

Hi Bastien,

Quoted 5 lines · Bastien Nocera
Quoted 2 lines · Bastien Nocera

Instead of trying to do it by hand. This also makes sure that relative paths aren't used by the agent.

This is still relevant and applicable.

Id leave as it is if that is not causing any bugs, we do intend to move away from glib at some point.

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw
Quoted 4 lines · Luiz Augusto von Dentz

Hi Bastien,

On Fri, Nov 24, 2017 at 4:12 PM, Bastien Nocera <[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines · Bastien Nocera
Quoted 2 lines

Instead of trying to do it by hand. This also makes sure that relative paths aren't used by the agent.

This is still relevant and applicable.

Id leave as it is if that is not causing any bugs, we do intend to move away from glib at some point.

I'm pretty sure that the existing code isn't secure and passing a relative path as the name will make it break out of the expected destination folder.