summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkiso.chang <kiso.chang@samsung.com>2021-02-16 18:42:41 +0900
committerkiso.chang <kiso.chang@samsung.com>2021-02-16 18:44:21 +0900
commit125269a6304cb80839ba1b4f326eee8d6f310408 (patch)
tree63ea5fa82d83e231ffe7ccb0b65ce82e966a33c1
parentd3ecdc8d4230a2d52b25b944e58b8a677da5486b (diff)
downloadfactory-reset-125269a6304cb80839ba1b4f326eee8d6f310408.tar.gz
factory-reset-125269a6304cb80839ba1b4f326eee8d6f310408.tar.bz2
factory-reset-125269a6304cb80839ba1b4f326eee8d6f310408.zip
Fix potential error in codes to insert null
Change-Id: I8939a923620809846ac9fb6ab09a2dd3ae0dec4a Signed-off-by: kiso.chang <kiso.chang@samsung.com>
-rw-r--r--src/rstsmack.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/rstsmack.c b/src/rstsmack.c
index 38d18d5..8ca51e1 100644
--- a/src/rstsmack.c
+++ b/src/rstsmack.c
@@ -75,6 +75,7 @@ static int parse_and_set(const char *srcfile)
FILE *fp;
int ret = 0;
char linebuf[PATH_MAX + 5 * SMACK_LABEL_LEN], pathname[PATH_MAX];
+ size_t linebuf_len;
char label[SMACK_LABEL_LEN + 1];
char *plabel; /* pointer of beginning smack label */
fp = fopen(srcfile, "r");
@@ -89,7 +90,13 @@ static int parse_and_set(const char *srcfile)
pathname[sizeof(pathname) - 1] = '\0';
plabel++;
} else {
- linebuf[strlen(linebuf) - 1] = '\0';
+ linebuf_len = strlen(linebuf);
+ if (linebuf_len > 0 && linebuf_len <= sizeof(linebuf))
+ linebuf[linebuf_len - 1] = '\0';
+ else {
+ LOGINFO("Invalid label length (%u)\n", linebuf_len);
+ return -1;
+ }
LOGINFO("no label, set label: %s, access=\"_\"(floor)\n", linebuf);
strncpy(label, "_\"", SMACK_LABEL_LEN);
set_label(linebuf, label, SMACK_LABEL_ACCESS);