On Fri, Jun 05, 2020 at 11:26:20PM +0800, Zhangfei Gao wrote:Yes, make sense, thanks Eric
You might want to use -ENAMETOOLONG instead of the strscpy return value of
On 2020/6/5 äå8:17, Herbert Xu wrote:
On Fri, Jun 05, 2020 at 05:34:32PM +0800, Zhangfei Gao wrote:Yes, good idea, we can use strscpy.
Will add a check after the copy.You don't need to do strlen. The function strlcpy returns the
ÂÂÂÂÂÂÂ strlcpy(interface.name, pdev->driver->name, sizeof(interface.name));
ÂÂÂÂÂÂÂ if (strlen(pdev->driver->name) != strlen(interface.name))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
length of the source string.
Better yet use strscpy which will even return an error for you.
+ÂÂÂÂÂÂ int ret;
-ÂÂÂÂÂÂ strncpy(interface.name, pdev->driver->name, sizeof(interface.name));
+ÂÂÂÂÂÂ ret = strscpy(interface.name, pdev->driver->name,
sizeof(interface.name));
+ÂÂÂÂÂÂ if (ret < 0)
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
-E2BIG.