From d6d41bf2989550b22efb0c5a1d355ae71934dd0f Mon Sep 17 00:00:00 2001 From: Janusz Kozerski Date: Mon, 28 Oct 2013 14:28:59 +0100 Subject: [PATCH] Use smack_label_length() internally instead strnlen() Use smack_label_length() to check correctness labels instead strnlen(). (cherry picked from commit 6d3fd3049e08377f75b554cedcd200286fbf359c) --- libsmack/libsmack.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libsmack/libsmack.c b/libsmack/libsmack.c index fb4fab3..1949f6f 100644 --- a/libsmack/libsmack.c +++ b/libsmack/libsmack.c @@ -170,8 +170,8 @@ int smack_accesses_add(struct smack_accesses *handle, const char *subject, { struct smack_rule *rule = NULL; - if (strnlen(subject, SMACK_LABEL_LEN + 1) > SMACK_LABEL_LEN || - strnlen(object, SMACK_LABEL_LEN + 1) > SMACK_LABEL_LEN) + if (smack_label_length(subject) < 0 || + smack_label_length(object) < 0) return -1; rule = calloc(sizeof(struct smack_rule), 1); @@ -200,8 +200,8 @@ int smack_accesses_add_modify(struct smack_accesses *handle, { struct smack_rule *rule = NULL; - if (strnlen(subject, SMACK_LABEL_LEN + 1) > SMACK_LABEL_LEN || - strnlen(object, SMACK_LABEL_LEN + 1) > SMACK_LABEL_LEN) + if (smack_label_length(subject) < 0 || + smack_label_length(object) < 0) return -1; rule = calloc(sizeof(struct smack_rule), 1); @@ -429,8 +429,7 @@ int smack_cipso_add_from_file(struct smack_cipso *cipso, int fd) label = strtok_r(buf, " \t\n", &ptr); level = strtok_r(NULL, " \t\n", &ptr); cat = strtok_r(NULL, " \t\n", &ptr); - if (label == NULL || level == NULL || - strlen(label) > SMACK_LABEL_LEN) + if (smack_label_length(label) < 0 || level == NULL) goto err_out; strcpy(mapping->label, label); @@ -571,8 +570,8 @@ int smack_set_label_for_self(const char *label) int fd; int ret; - len = strnlen(label, SMACK_LABEL_LEN + 1); - if (len > SMACK_LABEL_LEN) + len = smack_label_length(label); + if (len < 0) return -1; fd = open(SELF_LABEL_FILE, O_WRONLY); @@ -592,8 +591,8 @@ int smack_revoke_subject(const char *subject) int len; char path[PATH_MAX]; - len = strnlen(subject, SMACK_LABEL_LEN + 1); - if (len > SMACK_LABEL_LEN) + len = smack_label_length(subject); + if (len < 0) return -1; snprintf(path, sizeof path, "%s/revoke-subject", smackfs_mnt); -- 2.7.4