lib: posix: Fix Out-of-bound write to char array

memcpy copies upto (rc-1)th index but the write of NULL character
to the string is at (rc+1)th index skipping (rc)th index.
The fix addresses this as well.

CID: 186491

Fixes Issue #8280

Signed-off-by: Subramanian Meenakshi Sundaram <subbu147@gmail.com>
This commit is contained in:
Subramanian Meenakshi Sundaram 2018-06-08 12:11:13 -07:00 committed by Kumar Gala
commit 5193b5576f

View file

@ -297,7 +297,7 @@ struct dirent *readdir(DIR *dirp)
memcpy(pdirent.d_name, fdirent.name, rc);
/* Make sure the name is NULL terminated */
pdirent.d_name[rc + 1] = '\0';
pdirent.d_name[rc] = '\0';
return &pdirent;
}