frameworks/base
Revision | 6d7f3cd4026e7575796430add24e0b33ee3f25f9 (tree) |
---|---|
Time | 2020-04-14 23:46:52 |
Author | jgu21 <jinghui.gu@inte...> |
Commiter | Chih-Wei Huang |
Fix KW issues on PRC compatibility
Fix KW issues on PRC compatibility,introduced by below commit.
https://android.intel.com/#/c/484542/
Change-Id: Ib10899655dd2a18569387dbafbe33856acf5df59
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-26904
Signed-off-by: jgu21 <jinghui.gu@intel.com>
Reviewed-on: https://android.intel.com:443/487804
@@ -44,12 +44,15 @@ static const char* iaRelated[] = {"intel", "intl", "atom", "x86", "x64"}; | ||
44 | 44 | |
45 | 45 | ////////////////////////////////////////////////////////////////////// |
46 | 46 | void getConfig(const char* cfgFile , Vector<char*>& cfgVec) { |
47 | - FILE* fp = fopen(cfgFile, "r"); | |
48 | - assert(fp != NULL); | |
49 | 47 | int read = -1; |
50 | 48 | char *line = NULL; |
51 | 49 | size_t len = 0; |
52 | 50 | |
51 | + FILE* fp = fopen(cfgFile, "r"); | |
52 | + if (fp == NULL) { | |
53 | + return; | |
54 | + } | |
55 | + | |
53 | 56 | while ((read = getline(&line, &len, fp)) != -1) { |
54 | 57 | int i = 0 , j = 0; |
55 | 58 | char *cfgline = (char*)malloc(len); |
@@ -262,10 +265,10 @@ bool ABIPicker::compare(char* armRef, char* iaRef, | ||
262 | 265 | |
263 | 266 | Vector<char*>* iaRefList = getLibList(iaRef); |
264 | 267 | Vector<char*>* armRefList = getLibList(armRef); |
268 | + if (iaRefList == NULL || armRefList == NULL) { | |
269 | + break; | |
270 | + } | |
265 | 271 | |
266 | - // if contains the key words in iaRelated, just return true | |
267 | - assert(iaRefList != NULL); | |
268 | - assert(armRefList != NULL); | |
269 | 272 | if (isReliableLib(*iaRefList)) { |
270 | 273 | *result = iaRef; |
271 | 274 | break; |
@@ -341,27 +344,29 @@ bool ABIPicker::compareLibList(Vector<char*>& iaRefList, | ||
341 | 344 | // till the end, and the last result is equal |
342 | 345 | if (itArm == armRefList.end() && isEqual){ |
343 | 346 | return true; |
344 | - } else { | |
345 | - return false; | |
346 | 347 | } |
348 | + | |
349 | + return false; | |
347 | 350 | } |
348 | 351 | |
349 | 352 | bool ABIPicker::compare3rdPartyLibList( |
350 | 353 | char* iaRef, char* armRef, |
351 | 354 | size_t* iaIsvLibCount, size_t* armIsvLibCount) { |
355 | + bool result = true; | |
356 | + | |
352 | 357 | Vector<char*>* iaRefList = getLibList(iaRef); |
353 | 358 | Vector<char*>* armRefList = getLibList(armRef); |
354 | - assert(iaRefList != NULL); | |
355 | - assert(armRefList != NULL); | |
356 | - | |
357 | - Vector<char*>* armRef3rdPartyLibList = new Vector<char*>(); | |
358 | - Vector<char*>::iterator itArm = armRefList->begin(); | |
359 | + if (iaRefList == NULL || armRefList == NULL) { | |
360 | + return result; | |
361 | + } | |
359 | 362 | |
360 | - // Load thirdPartyso | |
361 | 363 | if (!thirdload) { |
362 | 364 | getConfig(THIRDPARTY, thirdPartySO); |
363 | 365 | thirdload = true; |
364 | 366 | } |
367 | + | |
368 | + Vector<char*>* armRef3rdPartyLibList = new Vector<char*>(); | |
369 | + Vector<char*>::iterator itArm = armRefList->begin(); | |
365 | 370 | while (itArm != armRefList->end()) { |
366 | 371 | char* armLibName = *itArm; |
367 | 372 | if (isInThirdPartySOList(armLibName)) { |
@@ -385,11 +390,10 @@ bool ABIPicker::compare3rdPartyLibList( | ||
385 | 390 | |
386 | 391 | itIa++; |
387 | 392 | } |
388 | - bool result = compareLibList(*iaRef3rdPartyLibList, *armRef3rdPartyLibList); | |
393 | + result = compareLibList(*iaRef3rdPartyLibList, *armRef3rdPartyLibList); | |
389 | 394 | |
390 | - //release the memory | |
391 | - free(armRef3rdPartyLibList); | |
392 | - free(iaRef3rdPartyLibList); | |
395 | + delete armRef3rdPartyLibList; | |
396 | + delete iaRef3rdPartyLibList; | |
393 | 397 | return result; |
394 | 398 | } |
395 | 399 |
@@ -472,11 +476,9 @@ bool ABIPicker::foundMixedELF(const char* abiName) { | ||
472 | 476 | ////////////////////////////////////////////////////////////////////// |
473 | 477 | ABIPicker::ABIPicker(const char* pkgName, Vector<ScopedUtfChars*> abiList) { |
474 | 478 | mLibList = new Vector<struct libInfo*>(); |
475 | - mpkgName = (char*)malloc(strlen(pkgName)+1); | |
479 | + mpkgName = strdup(pkgName); | |
476 | 480 | if (!mpkgName) { |
477 | 481 | P_LOG("ABIPicker Construct Allocated space fails"); |
478 | - } else { | |
479 | - snprintf(mpkgName, strlen(pkgName)+1, "%s", pkgName); | |
480 | 482 | } |
481 | 483 | Vector<ScopedUtfChars*>::iterator it = abiList.begin(); |
482 | 484 | while (it != abiList.end()) { |
@@ -537,12 +537,17 @@ com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace( | ||
537 | 537 | Vector<ScopedUtfChars*> supportedAbis; |
538 | 538 | |
539 | 539 | assert(apkdir_size < 256 - 15); |
540 | - strcpy(abiFlag, apkdir.c_str()); | |
540 | + if (strlcpy(abiFlag, apkdir.c_str(), 256) != apkdir.size()) { | |
541 | + return (jint)abiType; | |
542 | + } | |
543 | + | |
541 | 544 | abiFlag[apkdir_size] = '/'; |
542 | 545 | abiFlag[apkdir_size + 1] = '.'; |
543 | 546 | for (int i = 0; i < numAbis; i++) { |
544 | 547 | ScopedUtfChars* abiName = new ScopedUtfChars(env, |
545 | 548 | (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, i)); |
549 | + assert(abiName != NULL); | |
550 | + assert(abiName->c_str() != NULL); | |
546 | 551 | if (strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2) |
547 | 552 | == abiName->size()) { |
548 | 553 | if (access(abiFlag, F_OK) == 0) { |