[FIX] Map file parsing 12/61912/2 SRR_20160331 accepted/tizen/common/20160315.221031 accepted/tizen/ivi/20160314.105716 accepted/tizen/mobile/20160314.105625 accepted/tizen/tv/20160314.105643 accepted/tizen/wearable/20160314.105656 submit/tizen/20160314.042129
authorDmitry Kovalenko <d.kovalenko@samsung.com>
Fri, 11 Mar 2016 06:25:27 +0000 (09:25 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Fri, 11 Mar 2016 07:08:02 +0000 (10:08 +0300)
Add checking for length of device path

Change-Id: Ia1e9faeec5beee1de5db826f6f865ca5d61f878c
Signed-off-by: Dmitry Kovalenko <d.kovalenko@samsung.com>
helper/damaps.c

index 72f7cb0..b6d29fc 100755 (executable)
@@ -115,6 +115,8 @@ static int read_mapping_line(FILE *mapfile, struct map_t *m)
 {
        char ch1, ch2;
        int ret = 0;
+       size_t device_str_len = 0;
+       char tmp_path[PATH_MAX + 1];
 
        if (m == NULL) {
                PRINTERR("map_t param is NULL\n");
@@ -126,10 +128,17 @@ static int read_mapping_line(FILE *mapfile, struct map_t *m)
                     &m->endaddr,
                     (char *)m->permissions,
                     &m->offset,
-                    (char *)m->device,
+                    (char *)tmp_path,
                     &m->inode,
                     &ch1, &ch2);
 
+       strncpy(m->device, tmp_path, sizeof(m->device));
+       device_str_len = strnlen(tmp_path, sizeof(m->device));
+       if (device_str_len >= sizeof(m->device))
+               PRINTERR("device string is greater (%zu) than m->device size (%zu). Truncate.\n",
+                        device_str_len, sizeof(m->device));
+       m->device[sizeof(m->device) - 1] = '\0';
+
        m->is_instrument = 0;
        if (ret > 0 && ret != EOF) {
                int len = 0;