The event_note_list pointer is reassigned and its members are also reassigned. It should not be declared with the const qualifier.
The ptr variable, in unescape(), cannot be used to modify a string since it is initialized to the const char *buf input parameter. Rather than modifying buf, we can use ptr as a placeholder and use strndup() to allocate str. Later in the function a new, non-const pointer is used to modify str. These changes allow unescape() to still take a const char * as its input parameter. Signed-off-by: Tyler Hicks <[email protected]> --- src/aureport-options.c | 2 +- src/ausearch-common.h | 2 +- src/ausearch-lookup.c | 16 +++++++--------- src/ausearch-options.c | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/aureport-options.c b/src/aureport-options.c index 72a1d15..2af8714 100644 --- a/src/aureport-options.c +++ b/src/aureport-options.c @@ -42,7 +42,7 @@ int force_logs = 0; /* These are for compatibility with parser */ unsigned int event_id = -1; -const slist *event_node_list = NULL; +slist *event_node_list = NULL; const char *event_key = NULL; const char *event_filename = NULL; const char *event_exe = NULL; diff --git a/src/ausearch-common.h b/src/ausearch-common.h index 2ee1f33..95c9980 100644 --- a/src/ausearch-common.h +++ b/src/ausearch-common.h @@ -35,7 +35,7 @@ extern gid_t event_gid, event_egid; extern pid_t event_pid; extern int event_exact_match; extern uid_t event_uid, event_euid, event_loginuid; -const slist *event_node_list; +slist *event_node_list; extern const char *event_comm; extern const char *event_filename; extern const char *event_hostname; diff --git a/src/ausearch-lookup.c b/src/ausearch-lookup.c index cb13003..0c8f4bf 100644 --- a/src/ausearch-lookup.c +++ b/src/ausearch-lookup.c @@ -318,7 +318,8 @@ static unsigned char x2c(unsigned char *buf) char *unescape(const char *buf) { int len, i; - char saved, *ptr = buf, *str; + char *str, *strptr; + const char *ptr = buf; /* Find the end of the name */ if (*ptr == '(') { @@ -331,10 +332,7 @@ char *unescape(const char *buf) while (isxdigit(*ptr)) ptr++; } - saved = *ptr; - *ptr = 0; - str = strdup(buf); - *ptr = saved; + str = strndup(buf, ptr - buf); if (*buf == '(') return str; @@ -347,12 +345,12 @@ char *unescape(const char *buf) free(str); return NULL; } - ptr = str; + strptr = str; for (i=0; i<len; i+=2) { - *ptr = x2c((unsigned char *)&str[i]); - ptr++; + *strptr = x2c((unsigned char *)&str[i]); + strptr++; } - *ptr = 0; + *strptr = 0; return str; } diff --git a/src/ausearch-options.c b/src/ausearch-options.c index 769d8fa..06a85bb 100644 --- a/src/ausearch-options.c +++ b/src/ausearch-options.c @@ -68,7 +68,7 @@ const char *event_vmname = NULL; report_t report_format = RPT_DEFAULT; ilist *event_type; -const slist *event_node_list = NULL; +slist *event_node_list = NULL; struct nv_pair { int value; -- 1.7.10.4 -- Linux-audit mailing list [email protected] https://www.redhat.com/mailman/listinfo/linux-audit
