mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 14:25:52 +00:00
parser - Fix const char warnings
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@nxnw.org> Acked-by: Tyler Hicks <tyhicks@canonical.com>
This commit is contained in:
@@ -62,7 +62,7 @@ void aare_delete_ruleset(aare_ruleset_t *rules)
|
||||
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;
|
||||
|
@@ -35,10 +35,10 @@ typedef struct aare_ruleset aare_ruleset_t;
|
||||
|
||||
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);
|
||||
|
@@ -230,14 +230,14 @@ extern int names_only;
|
||||
extern int option;
|
||||
extern int current_lineno;
|
||||
extern dfaflags_t dfaflags;
|
||||
extern char *progname;
|
||||
extern const char *progname;
|
||||
extern 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;
|
||||
@@ -252,7 +252,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);
|
||||
@@ -267,7 +267,7 @@ extern int process_policy_ents(Profile *prof);
|
||||
|
||||
/* 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 */
|
||||
@@ -279,9 +279,9 @@ extern struct cond_entry *new_cond_entry(char *name, int eq, struct value_list *
|
||||
extern void free_cond_entry(struct cond_entry *ent);
|
||||
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 *processid(const 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);
|
||||
|
@@ -36,7 +36,7 @@ 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 *progname = __FILE__;
|
||||
char *profile_ns = NULL;
|
||||
char *profilename = NULL;
|
||||
char *current_filename = NULL;
|
||||
@@ -49,7 +49,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;
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
@@ -327,7 +327,7 @@ inline int sd_write64(sd_serialize *p, u64 b)
|
||||
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, void *b, int buf_size, char *name)
|
||||
|
||||
#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_serialize *p, void *b, int buf_size,
|
||||
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, char *b, int size, char *name)
|
||||
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_serialize *p)
|
||||
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_serialize *p)
|
||||
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;
|
||||
@@ -724,7 +724,7 @@ int __sd_serialize_profile(int option, Profile *prof)
|
||||
if (kernel_load) fd = open(filename, O_WRONLY);
|
||||
break;
|
||||
case OPTION_STDOUT:
|
||||
filename = "stdout";
|
||||
filename = strdup("stdout");
|
||||
fd = dup(1);
|
||||
break;
|
||||
case OPTION_OFILE:
|
||||
@@ -745,7 +745,6 @@ int __sd_serialize_profile(int option, Profile *prof)
|
||||
|
||||
error = 0;
|
||||
|
||||
if (option != OPTION_STDOUT && option != OPTION_OFILE)
|
||||
free(filename);
|
||||
|
||||
if (option == OPTION_REMOVE) {
|
||||
|
@@ -134,7 +134,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"
|
||||
@@ -298,7 +298,7 @@ static int handle_flag_table(optflag_table_t *table, const char *optarg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void display_dump(char *command)
|
||||
static void display_dump(const char *command)
|
||||
{
|
||||
display_version();
|
||||
printf("\n%s: --dump [Option]\n\n"
|
||||
@@ -310,7 +310,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"
|
||||
@@ -617,7 +617,7 @@ int find_subdomainfs_mountpoint(void)
|
||||
"mounted?\nUse --subdomainfs to override.\n"),
|
||||
MOUNTED_FS);
|
||||
} else {
|
||||
subdomainbase = DEFAULT_APPARMORFS;
|
||||
subdomainbase = strdup(DEFAULT_APPARMORFS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,7 +788,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;
|
||||
|
@@ -384,7 +384,7 @@ struct aa_network_entry *network_entry(const char *family, const char *type,
|
||||
return entry;
|
||||
};
|
||||
|
||||
char *processunquoted(char *string, int len)
|
||||
char *processunquoted(const char *string, int len)
|
||||
{
|
||||
char *tmp, *s;
|
||||
int l;
|
||||
@@ -420,7 +420,7 @@ char *processunquoted(char *string, int len)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
char *processid(char *string, int len)
|
||||
char *processid(const char *string, int len)
|
||||
{
|
||||
/* lexer should never call this fn if len <= 0 */
|
||||
assert(len > 0);
|
||||
@@ -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 = "";
|
||||
|
@@ -494,7 +494,7 @@ static int process_dfa_entry(aare_ruleset_t *dfarules, struct cod_entry *entry)
|
||||
/* 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_ruleset_t *dfarules, struct cod_entry *entry)
|
||||
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_ruleset_t *dfarules, struct cod_entry *entry)
|
||||
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_ruleset_t *dfarules, struct mnt_entry *entry)
|
||||
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_ruleset_t *dfarules, struct dbus_entry *entry
|
||||
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;
|
||||
|
@@ -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 *var)
|
||||
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(char *string, char *var_begin,
|
||||
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 *string)
|
||||
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 *prof)
|
||||
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);
|
||||
|
Reference in New Issue
Block a user