2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

The parser is not correctly clearing cache files if cache-loc is specified.

Fix this and unify creation and use of cacheloc so that we can hopefully
avoid these bugs.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
This commit is contained in:
John Johansen
2013-09-29 02:02:02 -07:00
parent f1a566ec6b
commit 9d375934dd

View File

@@ -1052,12 +1052,7 @@ int process_profile(int option, char *profilename)
*/
if ((profilename && option != OPTION_REMOVE) && !force_complain &&
!skip_cache) {
if (cacheloc) {
if (asprintf(&cachename, "%s/%s", cacheloc, basename)<0) {
PERROR(_("Memory allocation error."));
exit(1);
}
} else if (asprintf(&cachename, "%s/%s/%s", basedir, "cache", basename)<0) {
if (asprintf(&cachename, "%s/%s", cacheloc, basename)<0) {
PERROR(_("Memory allocation error."));
exit(1);
}
@@ -1161,19 +1156,7 @@ static int clear_cache_cb(DIR *dir, const char *path, struct stat *st,
static int clear_cache_files(const char *path)
{
char *cache;
int error;
if (asprintf(&cache, "%s/cache", path) == -1) {
perror("asprintf");
exit(1);
}
error = dirat_for_each(NULL, cache, NULL, clear_cache_cb);
free(cache);
return error;
return dirat_for_each(NULL, path, NULL, clear_cache_cb);
}
static int create_cache(const char *path, const char *features)
@@ -1201,7 +1184,6 @@ static void setup_flags(void)
{
char *cache_features_path = NULL;
char *cache_flags = NULL;
int rc;
/* Get the match string to determine type of regex support needed */
get_match_string();
@@ -1228,12 +1210,8 @@ static void setup_flags(void)
* - If cache/.features exists, and does not match flags_string,
* force cache reading/writing off.
*/
if (cacheloc)
rc = asprintf(&cache_features_path, "%s/.features", cacheloc);
else
rc = asprintf(&cache_features_path, "%s/cache/.features", basedir);
if (rc == -1) {
perror("asprintf");
if (asprintf(&cache_features_path, "%s/.features", cacheloc) == -1) {
PERROR(_("Memory allocation error."));
exit(1);
}
@@ -1241,7 +1219,7 @@ static void setup_flags(void)
if (cache_flags) {
if (strcmp(flags_string, cache_flags) != 0) {
if (write_cache && cond_clear_cache) {
if (clear_cache_files(basedir) ||
if (clear_cache_files(cacheloc) ||
create_cache(cache_features_path,
flags_string)) {
skip_read_cache = 1;
@@ -1286,8 +1264,16 @@ int main(int argc, char *argv[])
return retval;
}
/* create the cacheloc once and use it everywhere */
if (!cacheloc) {
if (asprintf(&cacheloc, "%s/cache", basedir) == -1) {
PERROR(_("Memory allocation error."));
exit(1);
}
}
if (force_clear_cache)
exit(clear_cache_files(basedir));
exit(clear_cache_files(cacheloc));
/* Check to make sure there is an interface to load policy */
if (!(UNPRIVILEGED_OPS) && (subdomainbase == NULL) &&