From 7c2fd7f0480d215a7838249276eeca4e46786917 Mon Sep 17 00:00:00 2001 From: Jarkko Sakkinen Date: Wed, 17 Nov 2010 14:38:32 -0800 Subject: [PATCH] Allocate object and subject from heap. This is preliminary step for implementing long labels. --- src/smack_rules.c | 14 ++++++++------ tests/check_xattr.c | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/smack_rules.c b/src/smack_rules.c index 0087cc1..efeb298 100644 --- a/src/smack_rules.c +++ b/src/smack_rules.c @@ -38,13 +38,13 @@ #define SMACK_ACC_LEN 4 struct smack_object { - char object[SMACK64_LEN + 1]; + char *object; unsigned ac; UT_hash_handle hh; }; struct smack_subject { - char subject[SMACK64_LEN + 1]; + char *subject; struct smack_object *objects; UT_hash_handle hh; }; @@ -246,15 +246,15 @@ static int update_rule(struct smack_subject **subjects, HASH_FIND_STR(*subjects, subject_str, s); if (s == NULL) { s = calloc(1, sizeof(struct smack_subject)); - strcpy(s->subject, subject_str); - HASH_ADD_STR(*subjects, subject, s); + s->subject = strdup(subject_str); + HASH_ADD_KEYPTR(hh, *subjects, s->subject, strlen(s->subject), s); } HASH_FIND_STR(s->objects, object_str, o); if (o == NULL) { o = calloc(1, sizeof(struct smack_object)); - strcpy(o->object, object_str); - HASH_ADD_STR(s->objects, object, o); + o->object = strdup(object_str); + HASH_ADD_KEYPTR(hh, s->objects, o->object, strlen(o->object), o); } o->ac = ac; @@ -271,9 +271,11 @@ static void destroy_rules(struct smack_subject **subjects) while (s->objects != NULL) { o = s->objects; HASH_DEL(s->objects, o); + free(o->object); free(o); } HASH_DEL(*subjects, s); + free(s->subject); free(s); } } diff --git a/tests/check_xattr.c b/tests/check_xattr.c index 9dba508..ceef60c 100644 --- a/tests/check_xattr.c +++ b/tests/check_xattr.c @@ -30,7 +30,7 @@ static int files_equal(const char *filename1, const char *filename2); START_TEST(test_set_smack_to_file) { FILE *file; - int rc; + int rc = NULL; char *smack; file = fopen("set_smack-dummy.txt", "w"); @@ -54,7 +54,7 @@ START_TEST(test_set_smack_to_file_symlink) { FILE *file; int rc; - char *smack; + char *smack = NULL; symlink("unknown.txt", "set_smack-symlink.txt"); @@ -75,7 +75,7 @@ START_TEST(test_set_smackexec_to_file) { FILE *file; int rc; - char *smack; + char *smack = NULL; file = fopen("set_smack-dummy.txt", "w"); fprintf(file, "dummy\n"); -- 2.7.4