Rule tokenizer fix
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 19 Dec 2013 09:07:57 +0000 (10:07 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 30 Jan 2014 11:47:56 +0000 (12:47 +0100)
[Issue#]       N/A
[Feature]      tokenize_rule may cause Segmentation Fault due to improper use of sscanf.
[Cause]        N/A
[Solution]     tokenize_rule rewritten
[Verification] Build, install, run tests.

Change-Id: Ief5ef1910ab459d82035887cbc8cda9d8897c734

src/common.c

index 6ea9705..af07e63 100644 (file)
@@ -115,10 +115,19 @@ int tokenize_rule(const char *const s_rule,
                  char s_object[],
                  char s_access[])
 {
-       if(sscanf(s_rule, "%s %s %s", s_subject, s_object, s_access) < 3) {
-               C_LOGE("RDB: Failed to tokenize the rule: %s", s_rule);
+       char tmp_s_dump[2] = "\0";
+       int ret = 0;
+
+       ret = sscanf(s_rule, "%" TOSTRING(SMACK_LABEL_LEN) "s%*[ \t\n\r]%" TOSTRING(SMACK_LABEL_LEN)
+                    "s%*[ \t\n\r]%" TOSTRING(ACC_LEN) "s%1s", s_subject, s_object,s_access,
+                    tmp_s_dump);
+
+       if (ret != 3) {
+               C_LOGE("RDB: Failed to tokenize the rule: <%s>. %d tokens needed, %d found.",
+                      s_rule, 3, ret);
                return PC_ERR_INVALID_OPERATION;
        }
+
        return PC_OPERATION_SUCCESS;
 }