Re: [Mesa-dev] [PATCH 8/9] anv: don't use strcpy for copying strings
On 14 July 2017 at 10:32, Grazvydas Ignotaswrote: > On Thu, Jul 13, 2017 at 8:09 PM, Lionel Landwerlin > wrote: >> CID: 1358935 >> Signed-off-by: Lionel Landwerlin >> --- >> src/intel/vulkan/anv_device.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c >> index 39c907e9f2d..d3607deccfc 100644 >> --- a/src/intel/vulkan/anv_device.c >> +++ b/src/intel/vulkan/anv_device.c >> @@ -895,7 +895,8 @@ void anv_GetPhysicalDeviceProperties( >>.sparseProperties = {0}, /* Broadwell doesn't do sparse. */ >> }; >> >> - strcpy(pProperties->deviceName, pdevice->name); >> + strncpy(pProperties->deviceName, pdevice->name, >> + VK_MAX_PHYSICAL_DEVICE_NAME_SIZE); > > It will still misbehave if pdevice->name is too long, maybe clear the > last byte manually or use snprintf? > The name comes from i965_pci_ids.h and the longest one seems to be around ~50 chars. Which is far less than the 256 above. If one wants to be really cautious, an assert should be enough? Mildly related: i965 codebase does to make use of the gen_get_device_name helper. At the same time the helper lacks the Braswell XXX naming fixup - aka get_bsw_model(). -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 8/9] anv: don't use strcpy for copying strings
On Thu, Jul 13, 2017 at 8:09 PM, Lionel Landwerlinwrote: > CID: 1358935 > Signed-off-by: Lionel Landwerlin > --- > src/intel/vulkan/anv_device.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c > index 39c907e9f2d..d3607deccfc 100644 > --- a/src/intel/vulkan/anv_device.c > +++ b/src/intel/vulkan/anv_device.c > @@ -895,7 +895,8 @@ void anv_GetPhysicalDeviceProperties( >.sparseProperties = {0}, /* Broadwell doesn't do sparse. */ > }; > > - strcpy(pProperties->deviceName, pdevice->name); > + strncpy(pProperties->deviceName, pdevice->name, > + VK_MAX_PHYSICAL_DEVICE_NAME_SIZE); It will still misbehave if pdevice->name is too long, maybe clear the last byte manually or use snprintf? GraÅžvydas ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 8/9] anv: don't use strcpy for copying strings
CID: 1358935 Signed-off-by: Lionel Landwerlin--- src/intel/vulkan/anv_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 39c907e9f2d..d3607deccfc 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -895,7 +895,8 @@ void anv_GetPhysicalDeviceProperties( .sparseProperties = {0}, /* Broadwell doesn't do sparse. */ }; - strcpy(pProperties->deviceName, pdevice->name); + strncpy(pProperties->deviceName, pdevice->name, + VK_MAX_PHYSICAL_DEVICE_NAME_SIZE); memcpy(pProperties->pipelineCacheUUID, pdevice->pipeline_cache_uuid, VK_UUID_SIZE); } -- 2.13.2 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev