crash-manager: Make permission handling in maps more abstract 23/221523/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 3 Jan 2020 08:16:48 +0000 (09:16 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 3 Jan 2020 14:04:31 +0000 (15:04 +0100)
This also fixes gcc9.2 build error.

Change-Id: Iae099a366063cd69cca840bd83121a8930d89088

src/crash-manager/so-info.c

index a0ae2dc..d95a927 100644 (file)
@@ -169,12 +169,20 @@ static int get_build_id(char *filename, char **build_id)
        return ret;
 }
 
-static int get_perms(char *line, char *perms)
+enum Perms {
+       PERM_READ = 1,
+       PERM_WRITE = 2,
+       PERM_EXEC = 4
+};
+
+/* Parses beginning of the maps file in the form: `addr1-addr2 r-xp size ...` */
+static int get_perms(char *line, enum Perms *perms)
 {
        char *first_space = strchr(line, ' ');
 
-       if (first_space > 0) {
-               strncpy(perms, first_space+1, 4);
+       if (first_space != 0 && strlen(first_space) > 4 /* eg. " r-xp" from example above */) {
+               char *p = first_space + 1;
+               *perms = (p[0] == 'r' ? PERM_READ : 0) | (p[1] == 'w' ? PERM_WRITE : 0) | (p[2] == 'x' ? PERM_EXEC : 0);
                return 0;
        } else
                return -1;
@@ -186,9 +194,9 @@ static int get_perms(char *line, char *perms)
  */
 static char *get_exe_filename(char *line)
 {
-       char perms[4];
+       enum Perms perms;
 
-       if (get_perms(line, perms) == 0 && perms[2] == 'x') {
+       if (get_perms(line, &perms) == 0 && (perms & PERM_EXEC)) {
                char *p = strstr(line, " /");
                if (p > 0)
                        return p+1;