diff options
author | Stefan Metzmacher <metze@samba.org> | 2011-02-24 11:15:06 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2011-02-24 12:29:56 +0100 |
commit | e2532816400f005574c7452e5c4e30a3a8067771 (patch) | |
tree | 76df258bff5fdf1fa184ecda7458c3e53d1a50a1 /source4/dynconfig | |
parent | 9bf1032cb773a3eda90d0c6d379c5938690209e8 (diff) | |
download | samba-e2532816400f005574c7452e5c4e30a3a8067771.tar.gz samba-e2532816400f005574c7452e5c4e30a3a8067771.tar.bz2 samba-e2532816400f005574c7452e5c4e30a3a8067771.zip |
s4:dynconfig: fix segfault in the set_dyn_*() functions
We should not try to call free on a const string (the default one).
Now we make sure that the dyn_* variable is never NULL
and only allocated if it's not the default value.
metze
Autobuild-User: Stefan Metzmacher <metze@samba.org>
Autobuild-Date: Thu Feb 24 12:29:56 CET 2011 on sn-devel-104
Diffstat (limited to 'source4/dynconfig')
-rw-r--r-- | source4/dynconfig/dynconfig.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/source4/dynconfig/dynconfig.c b/source4/dynconfig/dynconfig.c index 45b7b73720..65e57e0fc1 100644 --- a/source4/dynconfig/dynconfig.c +++ b/source4/dynconfig/dynconfig.c @@ -45,25 +45,38 @@ #define DEFINE_DYN_CONFIG_PARAM(name) \ const char *dyn_##name = name; \ \ - const char *get_dyn_##name(void) \ +bool is_default_dyn_##name(void) \ {\ - if (dyn_##name == NULL) {\ - return name;\ - }\ - return dyn_##name;\ + if (strcmp(name, dyn_##name) == 0) { \ + return true; \ + } \ + return false; \ }\ \ - const char *set_dyn_##name(const char *newpath) \ +const char *get_dyn_##name(void) \ {\ - if (dyn_##name) {\ - free(discard_const(dyn_##name)); \ - }\ - dyn_##name = strdup(newpath);\ return dyn_##name;\ }\ - bool is_default_dyn_##name(void) \ +\ +const char *set_dyn_##name(const char *newpath) \ {\ - return (dyn_##name == NULL);\ + if (newpath == NULL) { \ + return NULL; \ + } \ + if (strcmp(name, newpath) == 0) { \ + return dyn_##name; \ + } \ + newpath = strdup(newpath);\ + if (newpath == NULL) { \ + return NULL; \ + } \ + if (is_default_dyn_##name()) { \ + /* do not free a static string */ \ + } else if (dyn_##name) {\ + free(discard_const(dyn_##name)); \ + }\ + dyn_##name = newpath; \ + return dyn_##name;\ } /* these are in common with s3 */ |