net/virtio-user: fix string overflow
authorJianfeng Tan <jianfeng.tan@intel.com>
Wed, 29 Jun 2016 09:05:34 +0000 (09:05 +0000)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Tue, 5 Jul 2016 11:30:24 +0000 (13:30 +0200)
When parsing /proc/self/maps to get hugepage information, the string
was being copied with strcpy(), which could, theoretically but in fact
not possiblly, overflow the destination buffer. Anyway, to avoid the
false alarm, we replaced strncpy with snprintf for safely copying the
strings.

Coverity issue: 127484
Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
drivers/net/virtio/virtio_user/vhost_user.c

index a159ece..082e821 100644 (file)
@@ -181,7 +181,7 @@ get_hugepage_file_info(struct hugepage_file_info huges[], int max)
                }
                huges[idx].addr = v_start;
                huges[idx].size = v_end - v_start;
-               strcpy(huges[idx].path, tmp);
+               snprintf(huges[idx].path, PATH_MAX, "%s", tmp);
                idx++;
        }