xpenguins (2.2-7) 01_HOMEsegfault

Summary

 src/xpenguins_theme.c |   87 +++++++++++++++++++++++++++-----------------------
 1 file changed, 47 insertions(+), 40 deletions(-)

    
download this patch

Patch contents

#! /bin/sh /usr/share/dpatch/dpatch-run
## 01_HOMEsegfault.patch
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: No description.

@DPATCH@

--- bla/src/xpenguins_theme.orig	Tue Oct  2 00:36:12 2001
+++ bla/src/xpenguins_theme.c	Sat Nov 30 19:30:49 2002
@@ -153,28 +153,32 @@
   char *home_root = XPENGUINS_USER_DIRECTORY;
   char *themes = XPENGUINS_THEME_DIRECTORY;
   char *config = XPENGUINS_CONFIG;
-  char *config_path, *tmp_path;
+  char *config_path=NULL, *tmp_path, *ch;
   char *list = NULL;
   char **list_array = NULL;
   int list_len = 0;
   int i, string_length = 0;
   glob_t globbuf;
+  int sys_glob_mode=0;
   int n = 0;
-
-  /* First add themes from the users home directory */
-  string_length = strlen(home) + strlen(home_root)
-    + strlen(themes) + 2 + strlen(config) + 1;
-  config_path = malloc(string_length);
-  if (!config_path) {
-    xpenguins_out_of_memory();
-    return NULL;
-  }
-  snprintf(config_path, string_length, "%s%s%s/*%s",
-	   home, home_root, themes, config);
-  if (glob(config_path, 0, NULL, &globbuf) == GLOB_NOSPACE) {
-    free(config_path);
-    xpenguins_out_of_memory();
-    return NULL;
+ 
+  if (home != NULL) {
+    /* First add themes from the users home directory */
+    string_length = strlen(home) + strlen(home_root)
+      + strlen(themes) + 2 + strlen(config) + 1;
+    config_path = malloc(string_length);
+    if (!config_path) {
+      xpenguins_out_of_memory();
+      return NULL;
+    }
+    snprintf(config_path, string_length, "%s%s%s/*%s",
+	     home, home_root, themes, config);
+    if (glob(config_path, 0, NULL, &globbuf) == GLOB_NOSPACE) {
+      free(config_path);
+      xpenguins_out_of_memory();
+      return NULL;
+    }
+    sys_glob_mode=GLOB_APPEND;
   }
 
   /* Then add system themes */
@@ -192,7 +196,7 @@
   }
   snprintf(config_path, string_length, "%s%s/*%s",
 	   xpenguins_directory, themes, config);
-  if (glob(config_path, GLOB_APPEND, NULL, &globbuf) == GLOB_NOSPACE) {
+  if (glob(config_path, sys_glob_mode, NULL, &globbuf) == GLOB_NOSPACE) {
     free(config_path);
     xpenguins_out_of_memory();
     return NULL;
@@ -338,30 +342,33 @@
   int string_length = 0, root_length;
   struct stat stat_buf;
 
-  /* First look in $HOME/.xpenguins/themes for config */
-  root_length = strlen(home) + strlen(home_root) + strlen(themes) + 1;
-  string_length = root_length + strlen(name) + strlen(config) + 1;
-  config_path = malloc(string_length);
-  if (!config_path) {
-    xpenguins_out_of_memory();
-    return NULL;
-  }
-  snprintf(config_path, string_length, "%s%s%s/%s%s",
-	   home, home_root, themes, name, config);
-  /* Convert spaces to underscores */
-  ch = config_path + root_length;
-  while (*ch != '/') {
-    if (*ch == ' ') {
-      *ch = '_';
-    }
-    ++ch;
-  }
-  /* See if theme exists */
-  if (stat(config_path, &stat_buf) == 0) {
-    config_path[string_length-strlen(config)-1] = '\0';
-    return config_path;
+  if(home!=NULL) {
+    /* First look in $HOME/.xpenguins/themes for config */
+    root_length = strlen(home) + strlen(home_root) + strlen(themes) + 1;
+    string_length = root_length + strlen(name) + strlen(config) + 1;
+    config_path = malloc(string_length);
+    if (!config_path) {
+      xpenguins_out_of_memory();
+      return NULL;
+    }
+    snprintf(config_path, string_length, "%s%s%s/%s%s",
+	     home, home_root, themes, name, config);
+    /* Convert spaces to underscores */
+    ch = config_path + root_length;
+    while (*ch != '/') {
+      if (*ch == ' ') {
+	*ch = '_';
+      }
+      ++ch;
+    }
+    /* See if theme exists */
+    if (stat(config_path, &stat_buf) == 0) {
+      config_path[string_length-strlen(config)-1] = '\0';
+      return config_path;
+    }
+    /* Theme not found in users theme directory... */
   }
-  /* Theme not found in users theme directory... */
+
   /* Now look in [xpenguins_directory]/themes for config */
   root_length = strlen(xpenguins_directory) + strlen(themes) + 1;
   string_length = root_length + strlen(name) + strlen(config) + 1;