1 /**
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <dirent.h>
18 #include <dlfcn.h>
19 #include <signal.h>
20 #include <string>
21 #include <common.h>
22 #include <FDK_bitbuffer.h>
23 #define MAX_PATH_LENGTH 1035
24 
main()25 int main() {
26     FILE *fp;
27     char path[MAX_PATH_LENGTH];
28     void *libHandle;
29     static int (*real_FDK_getBitCnt)(HANDLE_FDK_BITBUF) = NULL;
30     fp = popen("find / -name libbluetooth.so 2>/dev/null ", "r");
31     if (fp == NULL) {
32         return EXIT_SUCCESS;
33     }
34     while (fgets(path, sizeof(path) - 1, fp) != NULL) {
35         path[strlen(path) - 1] = '\0'; /* remove \n */
36 
37         libHandle = dlopen(path, RTLD_LAZY);
38         if (libHandle) {
39             real_FDK_getBitCnt = (int (*)(
40                     HANDLE_FDK_BITBUF))dlsym(libHandle, "FDK_getBitCnt");
41             dlclose(libHandle);
42             if (real_FDK_getBitCnt) {
43                 pclose(fp);
44                 /* The symbol of function is present, it means there is no fix patch */
45                 return EXIT_VULNERABLE;
46             }
47         }
48     }
49     pclose(fp);
50     return EXIT_SUCCESS;
51 }
52