summaryrefslogtreecommitdiff
path: root/bus/config-parser.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2015-09-30 16:35:49 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2015-10-05 16:29:29 +0100
commitf830e14d3030c580bd2856f72bcffc0261387216 (patch)
treec0c5dd8af192f1749b89f226c22fff0d35ea6e44 /bus/config-parser.c
parenta52034266a60fb471e759a6c3349b11ce6494fdf (diff)
downloaddbus-f830e14d3030c580bd2856f72bcffc0261387216.tar.gz
Use DBusString for all relocation and install-root code
This means we handle OOM correctly, and makes it obvious that we are not overflowing buffers. This change does not affect the actual content of the strings. Instead of redefining DBUS_DATADIR to be a function call (which hides the fact that DBUS_DATADIR is used), this patch makes each use explicit: DBUS_DATADIR is always the #define from configure or cmake, before replacing the prefix. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83539 Tested-by: Ralf Habacker <ralf.habacker@freenet.de> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Diffstat (limited to 'bus/config-parser.c')
-rw-r--r--bus/config-parser.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/bus/config-parser.c b/bus/config-parser.c
index 3f59730b..3cd17cc7 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -3402,17 +3402,25 @@ test_default_session_servicedirs (void)
DBusList *link;
DBusString progs;
int i;
+ dbus_bool_t ret = FALSE;
#ifdef DBUS_WIN
const char *common_progs;
- char buffer[1024];
+ DBusString install_root_based;
- if (_dbus_get_install_root(buffer, sizeof(buffer)))
+ if (!_dbus_string_init (&install_root_based) ||
+ !_dbus_get_install_root (&install_root_based))
+ _dbus_assert_not_reached ("OOM getting install root");
+
+ if (_dbus_string_get_length (&install_root_based) > 0)
{
- strcat(buffer,DBUS_DATADIR);
- strcat(buffer,"/dbus-1/services");
- test_session_service_dir_matches[0] = buffer;
+ if (!_dbus_string_append (&install_root_based, DBUS_DATADIR) ||
+ !_dbus_string_append (&install_root_based, "/dbus-1/services"))
+ _dbus_assert_not_reached ("OOM appending to install root");
+
+ test_session_service_dir_matches[0] = _dbus_string_get_const_data (&install_root_based);
}
+
#endif
/* On Unix we don't actually use this variable, but it's easier to handle the
@@ -3426,16 +3434,11 @@ test_default_session_servicedirs (void)
if (common_progs)
{
if (!_dbus_string_append (&progs, common_progs))
- {
- _dbus_string_free (&progs);
- return FALSE;
- }
+ goto out;
if (!_dbus_string_append (&progs, "/dbus-1/services"))
- {
- _dbus_string_free (&progs);
- return FALSE;
- }
+ goto out;
+
test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
}
#endif
@@ -3457,8 +3460,7 @@ test_default_session_servicedirs (void)
printf ("error with default session service directories\n");
dbus_free (link->data);
_dbus_list_free_link (link);
- _dbus_string_free (&progs);
- return FALSE;
+ goto out;
}
dbus_free (link->data);
@@ -3485,8 +3487,7 @@ test_default_session_servicedirs (void)
printf ("more directories parsed than in match set\n");
dbus_free (link->data);
_dbus_list_free_link (link);
- _dbus_string_free (&progs);
- return FALSE;
+ goto out;
}
if (strcmp (test_session_service_dir_matches[i],
@@ -3497,8 +3498,7 @@ test_default_session_servicedirs (void)
test_session_service_dir_matches[i]);
dbus_free (link->data);
_dbus_list_free_link (link);
- _dbus_string_free (&progs);
- return FALSE;
+ goto out;
}
++i;
@@ -3511,13 +3511,17 @@ test_default_session_servicedirs (void)
{
printf ("extra data %s in the match set was not matched\n",
test_session_service_dir_matches[i]);
-
- _dbus_string_free (&progs);
- return FALSE;
+ goto out;
}
-
+
+ ret = TRUE;
+
+out:
_dbus_string_free (&progs);
- return TRUE;
+#ifdef DBUS_WIN
+ _dbus_string_free (&install_root_based);
+#endif
+ return ret;
}
static const char *test_system_service_dir_matches[] =