[1/2] bus/dpaa: fix build with gcc 9.0

Message ID 20181101131951.91459-1-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [1/2] bus/dpaa: fix build with gcc 9.0 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Ferruh Yigit Nov. 1, 2018, 1:19 p.m. UTC
  build error:
In function ‘fman_if_init’,
    .../drivers/bus/dpaa/base/fman/fman.c:186:2:
    error: ‘strncpy’ output may be truncated copying 4095 bytes from a
           string of length 4095 [-Werror=stringop-truncation]
    strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);

strncpy may result a not null-terminated string,
replaced it with rte_strscpy

Fixes: 5b22cf744689 ("bus/dpaa: introducing FMan configurations")
Cc: stable@dpdk.org

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 drivers/bus/dpaa/base/fman/fman.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Shreyansh Jain Nov. 1, 2018, 12:49 p.m. UTC | #1
On Thursday 01 November 2018 06:49 PM, Ferruh Yigit wrote:
> build error:
> In function ‘fman_if_init’,
>      .../drivers/bus/dpaa/base/fman/fman.c:186:2:
>      error: ‘strncpy’ output may be truncated copying 4095 bytes from a
>             string of length 4095 [-Werror=stringop-truncation]
>      strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
> 
> strncpy may result a not null-terminated string,
> replaced it with rte_strscpy
> 
> Fixes: 5b22cf744689 ("bus/dpaa: introducing FMan configurations")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---

I don't have gcc 9.0 environment to verify this, but the fix looks 
reasonable to me:

Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
  
Stephen Hemminger Nov. 1, 2018, 5:42 p.m. UTC | #2
On Thu,  1 Nov 2018 13:19:50 +0000
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> build error:
> In function ‘fman_if_init’,
>     .../drivers/bus/dpaa/base/fman/fman.c:186:2:
>     error: ‘strncpy’ output may be truncated copying 4095 bytes from a
>            string of length 4095 [-Werror=stringop-truncation]
>     strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
> 
> strncpy may result a not null-terminated string,
> replaced it with rte_strscpy
> 
> Fixes: 5b22cf744689 ("bus/dpaa: introducing FMan configurations")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Maybe just use strlcpy instead of a DPDK specific function.
That way if Gcc gets smarter it can check that as well.
  
Bruce Richardson Nov. 1, 2018, 5:45 p.m. UTC | #3
On Thu, Nov 01, 2018 at 10:42:31AM -0700, Stephen Hemminger wrote:
> On Thu,  1 Nov 2018 13:19:50 +0000
> Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> 
> > build error:
> > In function ‘fman_if_init’,
> >     .../drivers/bus/dpaa/base/fman/fman.c:186:2:
> >     error: ‘strncpy’ output may be truncated copying 4095 bytes from a
> >            string of length 4095 [-Werror=stringop-truncation]
> >     strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
> > 
> > strncpy may result a not null-terminated string,
> > replaced it with rte_strscpy
> > 
> > Fixes: 5b22cf744689 ("bus/dpaa: introducing FMan configurations")
> > Cc: stable@dpdk.org
> > 
> > Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> Maybe just use strlcpy instead of a DPDK specific function.
> That way if Gcc gets smarter it can check that as well.

+1
While I get the point of strscpy, if strlcpy is good enough for openbsd,
it's good enough for me! :-)
  
Ferruh Yigit Nov. 1, 2018, 6:21 p.m. UTC | #4
On 11/1/2018 5:45 PM, Bruce Richardson wrote:
> On Thu, Nov 01, 2018 at 10:42:31AM -0700, Stephen Hemminger wrote:
>> On Thu,  1 Nov 2018 13:19:50 +0000
>> Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>>
>>> build error:
>>> In function ‘fman_if_init’,
>>>     .../drivers/bus/dpaa/base/fman/fman.c:186:2:
>>>     error: ‘strncpy’ output may be truncated copying 4095 bytes from a
>>>            string of length 4095 [-Werror=stringop-truncation]
>>>     strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
>>>
>>> strncpy may result a not null-terminated string,
>>> replaced it with rte_strscpy
>>>
>>> Fixes: 5b22cf744689 ("bus/dpaa: introducing FMan configurations")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>
>> Maybe just use strlcpy instead of a DPDK specific function.
>> That way if Gcc gets smarter it can check that as well.
> 
> +1
> While I get the point of strscpy, if strlcpy is good enough for openbsd,
> it's good enough for me! :-)

I prefer strscpy but for both cases return value is not checked at all, so makes
hard to argue the benefit of the more proper return value J

So, as a rule of thumb are we saying strlcpy is dpdk preferred copy function?
  
Thomas Monjalon Nov. 1, 2018, 7:45 p.m. UTC | #5
01/11/2018 19:21, Ferruh Yigit:
> On 11/1/2018 5:45 PM, Bruce Richardson wrote:
> > On Thu, Nov 01, 2018 at 10:42:31AM -0700, Stephen Hemminger wrote:
> >> On Thu,  1 Nov 2018 13:19:50 +0000
> >> Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> >>
> >>> build error:
> >>> In function ‘fman_if_init’,
> >>>     .../drivers/bus/dpaa/base/fman/fman.c:186:2:
> >>>     error: ‘strncpy’ output may be truncated copying 4095 bytes from a
> >>>            string of length 4095 [-Werror=stringop-truncation]
> >>>     strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
> >>>
> >>> strncpy may result a not null-terminated string,
> >>> replaced it with rte_strscpy
> >>>
> >>> Fixes: 5b22cf744689 ("bus/dpaa: introducing FMan configurations")
> >>> Cc: stable@dpdk.org
> >>>
> >>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> >>
> >> Maybe just use strlcpy instead of a DPDK specific function.
> >> That way if Gcc gets smarter it can check that as well.
> > 
> > +1
> > While I get the point of strscpy, if strlcpy is good enough for openbsd,
> > it's good enough for me! :-)
> 
> I prefer strscpy but for both cases return value is not checked at all, so makes
> hard to argue the benefit of the more proper return value J
> 
> So, as a rule of thumb are we saying strlcpy is dpdk preferred copy function?

Yes
  

Patch

diff --git a/drivers/bus/dpaa/base/fman/fman.c b/drivers/bus/dpaa/base/fman/fman.c
index bdb700423..ddcd7d1f3 100644
--- a/drivers/bus/dpaa/base/fman/fman.c
+++ b/drivers/bus/dpaa/base/fman/fman.c
@@ -13,6 +13,7 @@ 
 #include <fman.h>
 #include <of.h>
 #include <rte_dpaa_logs.h>
+#include <rte_string_fns.h>
 
 #define QMI_PORT_REGS_OFFSET		0x400
 
@@ -183,7 +184,7 @@  fman_if_init(const struct device_node *dpa_node)
 	}
 	memset(__if, 0, sizeof(*__if));
 	INIT_LIST_HEAD(&__if->__if.bpool_list);
-	strncpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
+	rte_strscpy(__if->node_path, dpa_node->full_name, PATH_MAX - 1);
 	__if->node_path[PATH_MAX - 1] = '\0';
 
 	/* Obtain the MAC node used by this interface except macless */