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.1.0~52 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d3fd3049e08377f75b554cedcd200286fbf359c;p=platform%2Fupstream%2Fsmack.git Use smack_label_length() internally instead strnlen() Use smack_label_length() to check correctness labels instead strnlen(). --- diff --git a/libsmack/libsmack.c b/libsmack/libsmack.c index 4e93a33..9013f05 100644 --- a/libsmack/libsmack.c +++ b/libsmack/libsmack.c @@ -169,8 +169,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); @@ -199,8 +199,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); @@ -428,8 +428,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); @@ -570,8 +569,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); @@ -591,8 +590,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);