fix buffer underflow and overflow 45/74145/3 accepted/tizen/common/20160616.151525 accepted/tizen/ivi/20160616.002902 accepted/tizen/mobile/20160616.002832 accepted/tizen/tv/20160616.002814 accepted/tizen/wearable/20160616.002723 submit/tizen/20160615.073423
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 13 Jun 2016 02:41:12 +0000 (11:41 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Tue, 14 Jun 2016 10:08:48 +0000 (19:08 +0900)
Change-Id: I667f183f886be7b06bf41fef597fdafca86b3cbe
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
plugin/app2sd/src/app2sd_internals_utils.c

index b48558a..cada8e3 100644 (file)
@@ -622,10 +622,12 @@ char *_app2sd_generate_password(const char *pkgid)
 
        while (i < PASSWD_LEN) {
                seed = time(NULL);
-               char_1 = (rand_r(&seed) + pkgid[j--]) % ASCII_PASSWD_CHAR;
+               if (j > 0) j--;
+               char_1 = (rand_r(&seed) + pkgid[j]) % ASCII_PASSWD_CHAR;
                char_2 = rand_r(&seed) % ASCII_PASSWD_CHAR;
                passwd[i] = set[char_1];
-               passwd[i + 1] = set[(pkgid[j--]) * 2];
+               if (j > 0) j--;
+               passwd[i + 1] = set[((pkgid[j]) * 2) % ASCII_PASSWD_CHAR];
                if (i < PASSWD_LEN - 3)
                        passwd[i + 2] = set[char_2];
                i++;