libndctl: Fix a potentially non NUL-terminated string operation
Vishal Verma
maintainerPATCH 1/1 libndctl: Fix a potentially non NUL-terminated string operation
Static analysis warns that pread() doesn't NUL-terminate buffers, and that we shouldn't pass it directly to strcmp. The sysfs string should normally have the right termination, but for correctness in the library, we shouldn't rely on that. Replace the strcmp() calls in question with an explicit strncmp().
--- ndctl/lib/dimm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ndctl/lib/dimm.c +2 -2
@@ -825,7 +825,7 @@ NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm)break ; } -if (strcmp (buf,"overwrite" ) ==0 ) { +if (strncmp (buf,"overwrite" ,9 ) ==0 ) { rc =poll (&fds,1 ,-1 );if (rc <0 ) { rc = -errno;
@@ -839,7 +839,7 @@ NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm) } fds.revents =0 ; }else { -if (strcmp (buf,"disabled" ) ==0 ) +if (strncmp (buf,"disabled" ,8 ) ==0 ) rc =1 ;break ; }
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 10 lines · Vishal Verma
Static analysis warns that
pread()doesn't NUL-terminate buffers, and that we shouldn't pass it directly to strcmp. The sysfs string should normally have the right termination, but for correctness in the library, we shouldn't rely on that. Replace thestrcmp()calls in question with an explicitstrncmp().Fixes 3c0c7db045ec ("ndctl: add a wait-overwrite command")Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Quoted 19 lines
--- ndctl/lib/dimm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)ndctl/lib/dimm.c +1
-1@@ -825,7 +825,7 @@ NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm)break ; } -if (strcmp (buf,"overwrite" ) ==0 ) { +if (strncmp (buf,"overwrite" ,9 ) ==0 ) { rc =poll (&fds,1 ,-1 );if (rc <0 ) { rc = -errno;
ndctl/lib/dimm.c NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm) · line 845
Quoted 8 lines
ndctl/lib/dimm.c +1
-1@@ -839,7 +839,7 @@ NDCTL_EXPORT int ndctl_dimm_wait_overwrite(struct ndctl_dimm *dimm) } fds.revents =0 ; }else { -if (strcmp (buf,"disabled" ) ==0 ) +if (strncmp (buf,"disabled" ,8 ) ==0 ) rc =1 ;break ; }
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm