From 9b1970967eac7e9f57619e72573ac087cdc3f450 Mon Sep 17 00:00:00 2001 From: Richard Boulton Date: Sun, 7 Jan 2001 16:14:35 +0000 Subject: [PATCH] Folling wtays suggestion, I was going to start using xmlDocDump, to avoid a symlink attack on the temporary registry ... Original commit message from CVS: Folling wtays suggestion, I was going to start using xmlDocDump, to avoid a symlink attack on the temporary registry file. Unfortunately, xmlDocDump doesn't give any indication whether its successful, so I've #ifdefed this out and left the original in place. Since the tmp file is in /etc/gstreamer, this should be okay for the moment, but I shall ask the libxml people to add some way of getting the success value of DocDump so we can use that in future. --- tools/gstreamer-register.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/tools/gstreamer-register.c b/tools/gstreamer-register.c index 9487b930d2..9ae0728dee 100644 --- a/tools/gstreamer-register.c +++ b/tools/gstreamer-register.c @@ -20,9 +20,11 @@ * Boston, MA 02111-1307, USA. */ -#include #include +#include +#include + #include #include #include @@ -88,7 +90,7 @@ static int make_dir(const char * dirname) { return !mkdir(dirname, mode); } -void check_dir(const char * dirname) { +static void check_dir(const char * dirname) { if (!is_dir(dirname)) { if (!make_dir(dirname)) { g_print("Cannot create GStreamer registry directory `%s'", @@ -98,6 +100,32 @@ void check_dir(const char * dirname) { } } +static void save_registry(const char *destfile) { +#if 0 + FILE *fp; + + fp = fopen (destfile, "w"); + if (!fp) { + g_print("Cannot open `%s' to save new registry to.", destfile); + error_perm(); + } + + // FIXME: no way to check success of xmlDocDump, which is why + // this piece of code is ifdefed out. + xmlDocDump(fp, doc); + + if (!fclose(fp)) { + g_print("Cannot close `%s' having saved new registry.", destfile); + error_perm(); + } +#else + if (xmlSaveFile(destfile, doc) <= 0) { + g_print("Cannot save new registry to `%s'", destfile); + error_perm(); + } +#endif +} + int main(int argc,char *argv[]) { xmlDocPtr doc; @@ -119,11 +147,7 @@ int main(int argc,char *argv[]) gst_plugin_save_thyself(doc->root); // Save the registry to a tmp file. - if (xmlSaveFile(GLOBAL_REGISTRY_FILE_TMP, doc) <= 0) { - g_print("Cannot save new registry `%s'", - GLOBAL_REGISTRY_FILE_TMP); - error_perm(); - } + save_registry(GLOBAL_REGISTRY_FILE_TMP); // Make the tmp file live. move_file(GLOBAL_REGISTRY_FILE_TMP, GLOBAL_REGISTRY_FILE);