From: Janusz Kozerski Date: Mon, 28 Oct 2013 13:28:59 +0000 (+0100) Subject: Use smack_label_length() internally instead strnlen() X-Git-Tag: v1.0.2~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6d41bf2989550b22efb0c5a1d355ae71934dd0f;p=platform%2Fupstream%2Fsmack.git Use smack_label_length() internally instead strnlen() Use smack_label_length() to check correctness labels instead strnlen(). (cherry picked from commit 6d3fd3049e08377f75b554cedcd200286fbf359c) --- 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);