[apparmor] [patch] [parser] fix clearing of cache files
Tyler Hicks
tyhicks at canonical.com
Sat Sep 28 00:52:23 UTC 2013
On 2013-09-23 16:09:52, John Johansen wrote:
> 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 at canonical.com>
Acked-by: Tyler Hicks <tyhicks at canonical.com>
>
> ---
>
> === modified file 'parser/parser_main.c'
> --- parser/parser_main.c 2013-09-23 21:56:16 +0000
> +++ parser/parser_main.c 2013-09-23 22:23:20 +0000
> @@ -1086,12 +1086,7 @@
> */
> 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);
> }
> @@ -1260,18 +1255,8 @@
>
> static int clear_cache_files(const char *path)
> {
> - char *cache;
> int error;
> -
> - if (asprintf(&cache, "%s/cache", path) == -1) {
> - perror("asprintf");
> - exit(1);
> - }
> -
> - error = dir_for_each(cache, clear_cache_cb);
> -
> - free(cache);
> -
> + error = dir_for_each(path, clear_cache_cb);
> return error;
> }
>
> @@ -1300,7 +1285,6 @@
> {
> 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();
> @@ -1327,12 +1311,8 @@
> * - 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);
> }
>
> @@ -1340,7 +1320,7 @@
> 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;
> @@ -1385,8 +1365,16 @@
> 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) {
> - clear_cache_files(basedir);
> + clear_cache_files(cacheloc);
> exit(0);
> }
>
>
>
>
> --
> AppArmor mailing list
> AppArmor at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
-------------- 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/23edfb51/attachment.pgp>
More information about the AppArmor
mailing list