[apparmor] [PATCH 9/8 :) ] parser Fix const char warnings
Steve Beattie
steve at nxnw.org
Fri Sep 27 22:08:25 UTC 2013
On Fri, Sep 13, 2013 at 04:52:47PM -0700, Steve Beattie wrote:
> Finally, a patch of my own. This patch addresses a bunch of the compiler
> string conversion warnings that were introduced with the C++-ification
> patch.
>
> Signed-off-by: Steve Beattie <steve at nxnw.org>
>
> ---
> parser/libapparmor_re/aare_rules.cc | 4 ++--
> parser/libapparmor_re/aare_rules.h | 4 ++--
> parser/parser.h | 14 +++++++-------
> parser/parser_common.c | 6 +++---
> parser/parser_include.c | 10 +++++-----
> parser/parser_include.h | 2 +-
> parser/parser_interface.c | 18 +++++++++---------
> parser/parser_main.c | 8 ++++----
> parser/parser_misc.c | 8 ++++----
> parser/parser_regex.c | 12 +++++++-----
> parser/parser_variable.c | 34 +++++++++++++++++-----------------
> 11 files changed, 61 insertions(+), 59 deletions(-)
>
> Index: b/parser/parser.h
> ===================================================================
> --- a/parser/parser.h
> +++ b/parser/parser.h
> @@ -234,14 +234,14 @@ extern int names_only;
> extern int option;
> extern int current_lineno;
> extern dfaflags_t dfaflags;
> -extern char *progname;
> -extern char *subdomainbase;
> +extern const char *progname;
> +extern const char *subdomainbase;
> extern char *profilename;
> extern char *profile_ns;
> extern char *current_filename;
> extern FILE *ofile;
> extern int read_implies_exec;
> -extern void pwarn(char *fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
> +extern void pwarn(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
>
> /* from parser_main (cannot be used in tst builds) */
> extern int force_complain;
> @@ -256,7 +256,7 @@ extern void yyerror(const char *msg, ...
> extern int yylex(void);
>
> /* parser_include.c */
> -extern char *basedir;
> +extern const char *basedir;
>
> /* parser_regex.c */
> extern int process_regex(Profile *prof);
> @@ -271,7 +271,7 @@ extern int process_policy_ents(Profile *
>
> /* parser_variable.c */
> extern int process_variables(Profile *prof);
> -extern struct var_string *split_out_var(char *string);
> +extern struct var_string *split_out_var(const char *string);
> extern void free_var_string(struct var_string *var);
>
> /* parser_misc.c */
> @@ -284,8 +284,8 @@ extern void free_cond_entry(struct cond_
> extern void free_cond_list(struct cond_entry *ents);
> extern void print_cond_entry(struct cond_entry *ent);
> extern char *processid(char *string, int len);
> -extern char *processquoted(char *string, int len);
> -extern char *processunquoted(char *string, int len);
> +extern char *processquoted(const char *string, int len);
> +extern char *processunquoted(const char *string, int len);
> extern int get_keyword_token(const char *keyword);
> extern int name_to_capability(const char *keyword);
> extern int get_rlimit(const char *name);
> Index: b/parser/parser_common.c
> ===================================================================
> --- a/parser/parser_common.c
> +++ b/parser/parser_common.c
> @@ -36,8 +36,8 @@ int option = OPTION_ADD;
>
> dfaflags_t dfaflags = (dfaflags_t)(DFA_CONTROL_TREE_NORMAL | DFA_CONTROL_TREE_SIMPLE | DFA_CONTROL_MINIMIZE | DFA_CONTROL_MINIMIZE_HASH_TRANS);
>
> -char *subdomainbase = NULL;
> -char *progname = __FILE__;
> +const char *subdomainbase = NULL;
> +const char *progname = __FILE__;
> char *profile_ns = NULL;
> char *profilename = NULL;
> char *current_filename = NULL;
> @@ -50,7 +50,7 @@ int read_implies_exec = 1;
> int read_implies_exec = 0;
> #endif
>
> -void pwarn(char *fmt, ...)
> +void pwarn(const char *fmt, ...)
> {
> va_list arg;
> char *newfmt;
> Index: b/parser/parser_include.c
> ===================================================================
> --- a/parser/parser_include.c
> +++ b/parser/parser_include.c
> @@ -73,9 +73,9 @@ static char *stripblanks(char *s);
> /* default base directory is /etc/subdomain.d, it can be overriden
> with the -b option. */
>
> -char *basedir;
> -static char *default_basedir = "/etc/apparmor.d";
> -static char *old_basedir = "/etc/subdomain.d";
> +const char *basedir;
> +static const char *default_basedir = "/etc/apparmor.d";
> +static const char *old_basedir = "/etc/subdomain.d";
>
>
> /* set up basedir so that it can be overridden/used later. */
> @@ -130,7 +130,7 @@ void set_base_dir(char *dir)
> }
>
> /* Add a directory to the search path. */
> -int add_search_dir(char *dir)
> +int add_search_dir(const char *dir)
> {
> char *t;
> if (npath >= MAX_PATH) {
> @@ -149,7 +149,7 @@ int add_search_dir(char *dir)
> }
>
> /*strip trailing /'s */
> - while (t[strlen(t) - 1] == '/')
> + while ((char) t[strlen(t) - 1] == '/')
> t[strlen(t) - 1] = 0;
> path[npath] = t;
> npath++;
Since Tyler is reviewing this patch series, I should point out that,
thanks to review from Seth Arnold, I've dropped the bogus cast above
in add_search_dir() in my local version of this patch.
> Index: b/parser/parser_include.h
> ===================================================================
> --- a/parser/parser_include.h
> +++ b/parser/parser_include.h
> @@ -22,7 +22,7 @@
>
> extern int preprocess_only;
>
> -extern int add_search_dir(char *dir);
> +extern int add_search_dir(const char *dir);
> extern void init_base_dir(void);
> extern void set_base_dir(char *dir);
> extern void parse_default_paths(void);
> Index: b/parser/parser_main.c
> ===================================================================
> --- a/parser/parser_main.c
> +++ b/parser/parser_main.c
> @@ -132,7 +132,7 @@ static void display_version(void)
> parser_copyright);
> }
>
> -static void display_usage(char *command)
> +static void display_usage(const char *command)
> {
> display_version();
> printf("\nUsage: %s [options] [profile]\n\n"
> @@ -295,7 +295,7 @@ static int handle_flag_table(optflag_tab
> return 0;
> }
>
> -static void display_dump(char *command)
> +static void display_dump(const char *command)
> {
> display_version();
> printf("\n%s: --dump [Option]\n\n"
> @@ -307,7 +307,7 @@ static void display_dump(char *command)
> print_flag_table(dumpflag_table);
> }
>
> -static void display_optimize(char *command)
> +static void display_optimize(const char *command)
> {
> display_version();
> printf("\n%s: -O [Option]\n\n"
> @@ -831,7 +831,7 @@ out:
> return;
> }
>
> -static void get_flags_string(char **flags, char *flags_file) {
> +static void get_flags_string(char **flags, const char *flags_file) {
> char *pos;
> FILE *f = NULL;
> size_t size;
> Index: b/parser/libapparmor_re/aare_rules.cc
> ===================================================================
> --- a/parser/libapparmor_re/aare_rules.cc
> +++ b/parser/libapparmor_re/aare_rules.cc
> @@ -62,7 +62,7 @@ void aare_delete_ruleset(aare_ruleset_t
> aare_reset_matchflags();
> }
>
> -int aare_add_rule(aare_ruleset_t *rules, char *rule, int deny,
> +int aare_add_rule(aare_ruleset_t *rules, const char *rule, int deny,
> uint32_t perms, uint32_t audit, dfaflags_t flags)
> {
> return aare_add_rule_vec(rules, deny, perms, audit, 1, &rule, flags);
> @@ -96,7 +96,7 @@ void aare_reset_matchflags(void)
>
> int aare_add_rule_vec(aare_ruleset_t *rules, int deny,
> uint32_t perms, uint32_t audit,
> - int count, char **rulev, dfaflags_t flags)
> + int count, const char **rulev, dfaflags_t flags)
> {
> Node *tree = NULL, *accept;
> int exact_match;
> Index: b/parser/libapparmor_re/aare_rules.h
> ===================================================================
> --- a/parser/libapparmor_re/aare_rules.h
> +++ b/parser/libapparmor_re/aare_rules.h
> @@ -35,10 +35,10 @@ typedef struct aare_ruleset aare_ruleset
>
> aare_ruleset_t *aare_new_ruleset(int reverse);
> void aare_delete_ruleset(aare_ruleset_t *rules);
> -int aare_add_rule(aare_ruleset_t *rules, char *rule, int deny, uint32_t perms,
> +int aare_add_rule(aare_ruleset_t *rules, const char *rule, int deny, uint32_t perms,
> uint32_t audit, dfaflags_t flags);
> int aare_add_rule_vec(aare_ruleset_t *rules, int deny, uint32_t perms,
> - uint32_t audit, int count, char **rulev,
> + uint32_t audit, int count, const char **rulev,
> dfaflags_t flags);
> void *aare_create_dfa(aare_ruleset_t *rules, size_t *size, dfaflags_t flags);
> void aare_reset_matchflags(void);
> Index: b/parser/parser_regex.c
> ===================================================================
> --- a/parser/parser_regex.c
> +++ b/parser/parser_regex.c
> @@ -494,7 +494,7 @@ static int process_dfa_entry(aare_rulese
> /* add the pair rule */
> char lbuf[PATH_MAX + 8];
> int perms = AA_LINK_BITS & entry->mode;
> - char *vec[2];
> + const char *vec[2];
> int pos;
> vec[0] = tbuf;
> if (entry->link_name) {
> @@ -512,7 +512,7 @@ static int process_dfa_entry(aare_rulese
> return FALSE;
> }
> if (entry->mode & AA_CHANGE_PROFILE) {
> - char *vec[3];
> + const char *vec[3];
> char lbuf[PATH_MAX + 8];
> int index = 1;
>
> @@ -538,7 +538,7 @@ static int process_dfa_entry(aare_rulese
> if (entry->mode & (AA_USER_PTRACE | AA_OTHER_PTRACE)) {
> int mode = entry->mode & (AA_USER_PTRACE | AA_OTHER_PTRACE);
> if (entry->ns) {
> - char *vec[2];
> + const char *vec[2];
> vec[0] = entry->ns;
> vec[1] = entry->name;
> if (!aare_add_rule_vec(dfarules, 0, mode, 0, 2, vec, dfaflags))
> @@ -767,7 +767,8 @@ static int process_mnt_entry(aare_rulese
> char typebuf[PATH_MAX + 3];
> char flagsbuf[PATH_MAX + 3];
> char optsbuf[PATH_MAX + 3];
> - char *p, *vec[5];
> + char *p;
> + const char *vec[5];
> int count = 0;
> unsigned int flags, inv_flags;
>
> @@ -1033,7 +1034,8 @@ static int process_dbus_entry(aare_rules
> char pathbuf[PATH_MAX + 3];
> char ifacebuf[PATH_MAX + 3];
> char memberbuf[PATH_MAX + 3];
> - char *p, *vec[6];
> + char *p;
> + const char *vec[6];
>
> pattern_t ptype;
> int pos;
> Index: b/parser/parser_interface.c
> ===================================================================
> --- a/parser/parser_interface.c
> +++ b/parser/parser_interface.c
> @@ -327,7 +327,7 @@ inline int sd_write64(sd_serialize *p, u
> return 1;
> }
>
> -inline int sd_write_name(sd_serialize *p, char *name)
> +inline int sd_write_name(sd_serialize *p, const char *name)
> {
> long size = 0;
> PDEBUG("Writing name '%s'\n", name);
> @@ -362,7 +362,7 @@ inline int sd_write_blob(sd_serialize *p
>
> #define align64(X) (((size_t) (X) + (size_t) 7) & ~((size_t) 7))
> inline int sd_write_aligned_blob(sd_serialize *p, void *b, int buf_size,
> - char *name)
> + const char *name)
> {
> size_t pad;
> u32 tmp;
> @@ -381,7 +381,7 @@ inline int sd_write_aligned_blob(sd_seri
> return 1;
> }
>
> -static int sd_write_strn(sd_serialize *p, char *b, int size, char *name)
> +static int sd_write_strn(sd_serialize *p, char *b, int size, const char *name)
> {
> u16 tmp;
> if (!sd_write_name(p, name))
> @@ -396,12 +396,12 @@ static int sd_write_strn(sd_serialize *p
> return 1;
> }
>
> -inline int sd_write_string(sd_serialize *p, char *b, char *name)
> +inline int sd_write_string(sd_serialize *p, char *b, const char *name)
> {
> return sd_write_strn(p, b, strlen(b) + 1, name);
> }
>
> -inline int sd_write_struct(sd_serialize *p, char *name)
> +inline int sd_write_struct(sd_serialize *p, const char *name)
> {
> if (!sd_write_name(p, name))
> return 0;
> @@ -417,7 +417,7 @@ inline int sd_write_structend(sd_seriali
> return 1;
> }
>
> -inline int sd_write_array(sd_serialize *p, char *name, int size)
> +inline int sd_write_array(sd_serialize *p, const char *name, int size)
> {
> u16 tmp;
> if (!sd_write_name(p, name))
> @@ -437,7 +437,7 @@ inline int sd_write_arrayend(sd_serializ
> return 1;
> }
>
> -inline int sd_write_list(sd_serialize *p, char *name)
> +inline int sd_write_list(sd_serialize *p, const char *name)
> {
> if (!sd_write_name(p, name))
> return 0;
> @@ -733,7 +733,7 @@ int sd_serialize_profile(int option, Pro
> if (kernel_load) fd = open(filename, O_WRONLY);
> break;
> case OPTION_STDOUT:
> - filename = "stdout";
> + filename = strdup("stdout");
> fd = dup(1);
> break;
> case OPTION_OFILE:
> @@ -754,7 +754,7 @@ int sd_serialize_profile(int option, Pro
>
> error = 0;
>
> - if (option != OPTION_STDOUT && option != OPTION_OFILE)
> + if (option != OPTION_OFILE)
> free(filename);
>
> if (option == OPTION_REMOVE) {
> Index: b/parser/parser_misc.c
> ===================================================================
> --- a/parser/parser_misc.c
> +++ b/parser/parser_misc.c
> @@ -384,7 +384,7 @@ struct aa_network_entry *network_entry(c
> return entry;
> };
>
> -char *processunquoted(char *string, int len)
> +char *processunquoted(const char *string, int len)
> {
> char *tmp, *s;
> int l;
> @@ -433,7 +433,7 @@ char *processid(char *string, int len)
> /* rewrite a quoted string substituting escaped characters for the
> * real thing. Strip the quotes around the string */
>
> -char *processquoted(char *string, int len)
> +char *processquoted(const char *string, int len)
> {
> char *tmp, *s;
> int l;
> @@ -1235,7 +1235,7 @@ int test_str_to_boolean(void)
> int test_processunquoted(void)
> {
> int rc = 0;
> - char *teststring, *processedstring;
> + const char *teststring, *processedstring;
>
> teststring = "";
> MY_TEST(strcmp(teststring, processunquoted(teststring, strlen(teststring))) == 0,
> @@ -1263,7 +1263,7 @@ int test_processunquoted(void)
> int test_processquoted(void)
> {
> int rc = 0;
> - char *teststring, *processedstring;
> + const char *teststring, *processedstring;
> char *out;
>
> teststring = "";
> Index: b/parser/parser_variable.c
> ===================================================================
> --- a/parser/parser_variable.c
> +++ b/parser/parser_variable.c
> @@ -32,9 +32,9 @@
> #include "mount.h"
> #include "dbus.h"
>
> -static inline char *get_var_end(char *var)
> +static inline const char *get_var_end(const char *var)
> {
> - char *eptr = var;
> + const char *eptr = var;
>
> while (*eptr) {
> if (*eptr == '}')
> @@ -52,8 +52,8 @@ static inline char *get_var_end(char *va
> return NULL; /* no terminating '}' */
> }
>
> -static struct var_string *split_string(char *string, char *var_begin,
> - char *var_end)
> +static struct var_string *split_string(const char *string, const char *var_begin,
> + const char *var_end)
> {
> struct var_string *n = (struct var_string *) calloc(1, sizeof(struct var_string));
> unsigned int offset = strlen("@{");
> @@ -75,10 +75,10 @@ static struct var_string *split_string(c
> return n;
> }
>
> -struct var_string *split_out_var(char *string)
> +struct var_string *split_out_var(const char *string)
> {
> struct var_string *n = NULL;
> - char *sptr;
> + const char *sptr;
> BOOL bEscape = 0; /* flag to indicate escape */
>
> if (!string) /* shouldn't happen */
> @@ -99,7 +99,7 @@ struct var_string *split_out_var(char *s
> if (bEscape) {
> bEscape = FALSE;
> } else if (*(sptr + 1) == '{') {
> - char *eptr = get_var_end(sptr + 2);
> + const char *eptr = get_var_end(sptr + 2);
> if (!eptr)
> break; /* no variable end found */
> if (eptr == sptr + 2) {
> @@ -325,8 +325,8 @@ int process_profile_variables(Profile *p
> int test_get_var_end(void)
> {
> int rc = 0;
> - char *retchar;
> - char *testchar;
> + const char *retchar;
> + const char *testchar;
>
> testchar = "TRUE}";
> retchar = get_var_end(testchar);
> @@ -356,9 +356,9 @@ int test_split_string(void)
> int rc = 0;
> char *tst_string, *var_start, *var_end;
> struct var_string *ret_struct;
> - char *prefix = "abcdefg";
> - char *var = "boogie";
> - char *suffix = "suffixication";
> + const char *prefix = "abcdefg";
> + const char *var = "boogie";
> + const char *suffix = "suffixication";
>
> asprintf(&tst_string, "%s@{%s}%s", prefix, var, suffix);
> var_start = tst_string + strlen(prefix);
> @@ -404,11 +404,11 @@ int test_split_out_var(void)
> int rc = 0;
> char *tst_string, *tmp;
> struct var_string *ret_struct;
> - char *prefix = "abcdefg";
> - char *var = "boogie";
> - char *var2 = "V4rW1thNum5";
> - char *var3 = "boogie_board";
> - char *suffix = "suffixication";
> + const char *prefix = "abcdefg";
> + const char *var = "boogie";
> + const char *var2 = "V4rW1thNum5";
> + const char *var3 = "boogie_board";
> + const char *suffix = "suffixication";
>
> /* simple case */
> asprintf(&tst_string, "%s@{%s}%s", prefix, var, suffix);
>
> --
> Steve Beattie
> <sbeattie at ubuntu.com>
> http://NxNW.org/~steve/
> --
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
--
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20130927/357da7f8/attachment-0001.pgp>
More information about the AppArmor
mailing list