From: Dmitry Kovalenko Date: Fri, 11 Mar 2016 06:25:27 +0000 (+0300) Subject: [FIX] Map file parsing X-Git-Tag: SRR_20160331 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Ftags%2FSRR_20160331;p=platform%2Fcore%2Fsystem%2Fswap-probe.git [FIX] Map file parsing Add checking for length of device path Change-Id: Ia1e9faeec5beee1de5db826f6f865ca5d61f878c Signed-off-by: Dmitry Kovalenko --- diff --git a/helper/damaps.c b/helper/damaps.c index 72f7cb0..b6d29fc 100755 --- a/helper/damaps.c +++ b/helper/damaps.c @@ -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;