Include packages in so_info file that are associated with *.ni.dll 61/231561/3
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 22 Apr 2020 10:04:25 +0000 (12:04 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 28 Apr 2020 10:55:24 +0000 (12:55 +0200)
Change-Id: I114a866da9fc70915b616b39869d23cb9e7f22c7

src/crash-manager/so-info.c

index b3f76a9..0c5b7b9 100644 (file)
  * limitations under the License.
  */
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <libgen.h>
 #include <limits.h>
 #include <string.h>
 #include <elf.h>
@@ -381,6 +383,72 @@ char *get_app_name_from_path(const char *file_path)
        return NULL;
 }
 
+bool replace_suffix(char *string, char *suffix, char *replace, char* buff, size_t len)
+{
+       assert(string);
+       assert(suffix);
+       assert(replace);
+       assert(buff);
+
+       char *sub = strstr(string, suffix);
+       if (sub == NULL)
+               return false;
+
+       size_t prefix_len = sub - string;
+       if (len < prefix_len) {
+               _I("Buffer too small");
+               return false;
+       }
+
+       strncpy(buff, string, prefix_len);
+       if (snprintf(&buff[prefix_len], len, "%s", replace) < 0) {
+               _E("Suffix replaceing error (%s %s -> %s): %m", string, suffix, replace);
+               return false;
+       }
+
+       return true;
+}
+
+bool correct_file_path(const char *file_path, char *buff, size_t len)
+{
+       assert(file_path);
+       assert(buff);
+
+       bool result = false;
+       char file_path_copy[PATH_MAX];
+
+       strncpy(file_path_copy, file_path, sizeof(file_path_copy) - 1);
+
+       char *file_name = basename(file_path_copy);
+       char dll_name[PATH_MAX];
+
+       if (!replace_suffix(file_name, ".ni.dll", ".dll", dll_name, sizeof(dll_name)))
+               return false;
+
+       _D("Correcting the file: %s", file_path);
+
+       strncpy(file_path_copy, file_path, sizeof(file_path_copy) - 1);
+       char *dir_name = dirname(file_path_copy);
+
+       if (!file_exists_in_dir(dir_name, dll_name)) {
+               char tmp_dir_name[PATH_MAX];
+
+               strncpy(tmp_dir_name, dir_name, sizeof(tmp_dir_name) - 1);
+               dir_name = dirname(tmp_dir_name);
+
+               if (!file_exists_in_dir(dir_name, dll_name)) {
+                       _D("Cannot find the corresponding dll file for: %s", file_path);
+                       return false;
+               }
+       }
+
+       result = snprintf(buff, len, "%s/%s", dir_name, dll_name) > 0;
+       if (!result)
+               _E("Can not correct file path %s: %m", file_path);
+
+       return result;
+}
+
 void get_and_save_so_info(char *map_path, char *out_path)
 {
        FILE *f = fopen(out_path, "w");
@@ -396,12 +464,16 @@ void get_and_save_so_info(char *map_path, char *out_path)
 
        for (GSList *iterator = file_list; iterator; iterator = iterator->next) {
                char *file_path = (char *)iterator->data;
-
+               char modified_file_path[PATH_MAX];
                char *build_id = NULL;
-               if (is_dotnet_file(file_path))
+
+               if (is_dotnet_file(file_path)) {
                        build_id = strdup("");
-               else if (get_build_id(file_path, &build_id) <= 0 || build_id == NULL)
+                       if (correct_file_path(file_path, modified_file_path, sizeof(modified_file_path)))
+                               file_path = modified_file_path;
+               } else if (get_build_id(file_path, &build_id) <= 0 || build_id == NULL) {
                        continue;
+               }
 
                char *rpm_info = get_rpm_info(ts, file_path);
                if (rpm_info == NULL) {