1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

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
This commit is contained in:
Stefan Metzmacher 2011-02-24 11:15:06 +01:00
parent 9bf1032cb7
commit e253281640

View File

@ -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 (strcmp(name, dyn_##name) == 0) { \
return true; \
} \
return false; \
}\
\
const char *get_dyn_##name(void) \
{\
if (dyn_##name == NULL) {\
return name;\
}\
return dyn_##name;\
}\
\
const char *set_dyn_##name(const char *newpath) \
const char *set_dyn_##name(const char *newpath) \
{\
if (dyn_##name) {\
free(discard_const(dyn_##name)); \
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 = strdup(newpath);\
dyn_##name = newpath; \
return dyn_##name;\
}\
bool is_default_dyn_##name(void) \
{\
return (dyn_##name == NULL);\
}
/* these are in common with s3 */