mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
dmuci: fix returning of invalid pointers
This fixes segfaults and pointers with invalid strings for: - dmuci_add_section - dmuci_set_value_by_section - dmuci_set_value Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
This commit is contained in:
parent
1cec0190fd
commit
fb12136904
2 changed files with 34 additions and 35 deletions
|
|
@ -405,7 +405,7 @@ int dmuci_change_packages(struct list_head *clist)
|
|||
}
|
||||
|
||||
/**** UCI SET *****/
|
||||
char *dmuci_set_value(char *package, char *section, char *option, char *value)
|
||||
const char *dmuci_set_value(char *package, char *section, char *option, char *value)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
|
||||
|
|
@ -422,13 +422,13 @@ char *dmuci_set_value(char *package, char *section, char *option, char *value)
|
|||
return "";
|
||||
}
|
||||
|
||||
char *dmuci_set_varstate_value(char *package, char *section, char *option, char *value)
|
||||
const char *dmuci_set_varstate_value(char *package, char *section, char *option, char *value)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
|
||||
uci_add_delta_path(uci_varstate_ctx, uci_varstate_ctx->savedir);
|
||||
uci_set_savedir(uci_varstate_ctx, VARSTATE_CONFIG);
|
||||
|
||||
|
||||
if (dmuci_lookup_ptr(uci_varstate_ctx, &ptr, package, section, option, value)) {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -471,29 +471,27 @@ int dmuci_del_list_value(char *package, char *section, char *option, char *value
|
|||
}
|
||||
|
||||
/****** UCI ADD *******/
|
||||
int dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value)
|
||||
const char * dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value)
|
||||
{
|
||||
struct uci_ptr ptr = {0};
|
||||
const char *val = "";
|
||||
|
||||
*s = NULL;
|
||||
|
||||
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL)) {
|
||||
*value = "";
|
||||
return -1;
|
||||
}
|
||||
if (uci_add_section(uci_ctx, ptr.p, stype, s) != UCI_OK) {
|
||||
*value = "";
|
||||
return -1;
|
||||
}
|
||||
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL) == 0
|
||||
&& uci_add_section(uci_ctx, ptr.p, stype, s) == UCI_OK)
|
||||
val = dmstrdup((*s)->e.name);
|
||||
|
||||
*value = dmstrdup((*s)->e.name); // MEM WILL BE FREED IN DMMEMCLEAN
|
||||
return 0;
|
||||
*value = val;
|
||||
return val;
|
||||
}
|
||||
|
||||
int dmuci_add_section_and_rename(char *package, char *stype, struct uci_section **s, char **value)
|
||||
const char * dmuci_add_section_and_rename(char *package, char *stype, struct uci_section **s, char **value)
|
||||
{
|
||||
int r = dmuci_add_section(package, stype, s, value);
|
||||
dmuci_rename_section_by_section(*s, *value);
|
||||
return r;
|
||||
const char *name = dmuci_add_section(package, stype, s, value);
|
||||
|
||||
dmuci_rename_section_by_section(*s, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
int dmuci_add_state_section(char *package, char *stype, struct uci_section **s, char **value)
|
||||
|
|
@ -639,7 +637,7 @@ int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct
|
|||
}
|
||||
|
||||
/**** UCI SET by section pointer ****/
|
||||
char *dmuci_set_value_by_section(struct uci_section *s, char *option, char *value)
|
||||
const char *dmuci_set_value_by_section(struct uci_section *s, char *option, char *value)
|
||||
{
|
||||
struct uci_ptr up = {0};
|
||||
|
||||
|
|
|
|||
|
|
@ -159,16 +159,16 @@ int dmuci_commit(void);
|
|||
int dmuci_revert_package(char *package);
|
||||
int dmuci_revert(void);
|
||||
int dmuci_change_packages(struct list_head *clist);
|
||||
char *dmuci_set_value(char *package, char *section, char *option, char *value);
|
||||
const char *dmuci_set_value(char *package, char *section, char *option, char *value);
|
||||
int dmuci_add_list_value(char *package, char *section, char *option, char *value);
|
||||
int dmuci_del_list_value(char *package, char *section, char *option, char *value);
|
||||
int dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value);
|
||||
int dmuci_add_section_and_rename(char *package, char *stype, struct uci_section **s, char **value);
|
||||
const char * dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value);
|
||||
const char * dmuci_add_section_and_rename(char *package, char *stype, struct uci_section **s, char **value);
|
||||
int dmuci_delete(char *package, char *section, char *option, char *value);
|
||||
int dmuci_lookup_ptr_by_section(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_section *s, char *option, char *value);
|
||||
int dmuci_get_value_by_section_string(struct uci_section *s, char *option, char **value);
|
||||
int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_list **value);
|
||||
char *dmuci_set_value_by_section(struct uci_section *s, char *option, char *value);
|
||||
const char *dmuci_set_value_by_section(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_delete_by_section(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_delete_by_section_unnamed(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_add_list_value_by_section(struct uci_section *s, char *option, char *value);
|
||||
|
|
@ -176,13 +176,13 @@ int dmuci_del_list_value_by_section(struct uci_section *s, char *option, char *v
|
|||
struct uci_section *dmuci_walk_section(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
|
||||
struct uci_section *dmuci_walk_state_section(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
|
||||
struct uci_section *dmuci_walk_section_bbfdm(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
|
||||
char *dmuci_set_value_by_section_bbfdm(struct uci_section *s, char *option, char *value);
|
||||
const char *dmuci_set_value_by_section_bbfdm(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_delete_by_section_unnamed_bbfdm(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_add_section_bbfdm(char *package, char *stype, struct uci_section **s, char **value);
|
||||
const char * dmuci_add_section_bbfdm(char *package, char *stype, struct uci_section **s, char **value);
|
||||
int dmuci_delete_bbfdm(char *package, char *section, char *option, char *value);
|
||||
int dmuci_add_state_section(char *package, char *stype, struct uci_section **s, char **value);
|
||||
char *dmuci_set_varstate_value(char *package, char *section, char *option, char *value);
|
||||
char *dmuci_set_value_bbfdm(char *package, char *section, char *option, char *value);
|
||||
const char * dmuci_set_varstate_value(char *package, char *section, char *option, char *value);
|
||||
const char * dmuci_set_value_bbfdm(char *package, char *section, char *option, char *value);
|
||||
int dmuci_delete_by_section_bbfdm(struct uci_section *s, char *option, char *value);
|
||||
int dmuci_rename_section_by_section(struct uci_section *s, char *value);
|
||||
int dmuci_exit_bbfdm(void);
|
||||
|
|
@ -239,12 +239,12 @@ int dmuci_get_option_value_list_##UCI_PATH(char *package, char *section, char *o
|
|||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
char *dmuci_set_value_##UCI_PATH(char *package, char *section, char *option, char *value) \
|
||||
const char *dmuci_set_value_##UCI_PATH(char *package, char *section, char *option, char *value) \
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
save_uci_ctx = uci_ctx; \
|
||||
uci_ctx = uci_ctx_##UCI_PATH; \
|
||||
char *res = dmuci_set_value(package, section, option, value); \
|
||||
const char *res = dmuci_set_value(package, section, option, value); \
|
||||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
|
|
@ -266,14 +266,15 @@ int dmuci_del_list_value_##UCI_PATH(char *package, char *section, char *option,
|
|||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
int dmuci_add_section_##UCI_PATH(char *package, char *stype, struct uci_section **s, char **value)\
|
||||
const char * dmuci_add_section_##UCI_PATH(char *package, char *stype, struct uci_section **s, char **value)\
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
const char *name; \
|
||||
save_uci_ctx = uci_ctx; \
|
||||
uci_ctx = uci_ctx_##UCI_PATH; \
|
||||
int res = dmuci_add_section(package, stype, s, value); \
|
||||
uci_ctx = uci_ctx_##UCI_PATH; \
|
||||
name = dmuci_add_section(package, stype, s, value); \
|
||||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
return name; \
|
||||
}\
|
||||
int dmuci_delete_##UCI_PATH(char *package, char *section, char *option, char *value) \
|
||||
{\
|
||||
|
|
@ -284,12 +285,12 @@ int dmuci_delete_##UCI_PATH(char *package, char *section, char *option, char *va
|
|||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
char *dmuci_set_value_by_section_##UCI_PATH(struct uci_section *s, char *option, char *value)\
|
||||
const char *dmuci_set_value_by_section_##UCI_PATH(struct uci_section *s, char *option, char *value)\
|
||||
{\
|
||||
struct uci_context *save_uci_ctx; \
|
||||
save_uci_ctx = uci_ctx; \
|
||||
uci_ctx = uci_ctx_##UCI_PATH; \
|
||||
char *res = dmuci_set_value_by_section(s, option, value); \
|
||||
const char *res = dmuci_set_value_by_section(s, option, value); \
|
||||
uci_ctx = save_uci_ctx; \
|
||||
return res; \
|
||||
}\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue