libselinux: drop usage of _D_ALLOC_NAMLEN
PATCH 1/1 libselinux: drop usage of _D_ALLOC_NAMLEN
From: William Roberts <[email protected]>
_D_ALLOC_NAMLEN is not very portable. Currently, the code mallocs based on _D_ALLOC_NAMLEN() and then strcpy's dirent d_name into the buffer. Instead, just use strdup.
Change-Id I5c8ca47da2c593ea2726caba5781f5e9d9d910ae
Signed-off-by William Roberts <[email protected]>
--- libselinux/src/booleans.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libselinux/src/booleans.c +1 -2
@@ -63,12 +63,11 @@ int security_get_boolean_names(char ***names, int *len) }for (i =0 ; i < *len; i++) { - n[i] = (char *)malloc (_D_ALLOC_NAMLEN (namelist[i])); + n[i] =strdup (namelist[i]->d_name);if (!n[i]) { rc =-1 ; goto bad_freen; } -strcpy (n[i], namelist[i]->d_name); } rc =0 ; *names = n;
Signature · 1 line
1.9.1
Stephen Smalley
AppliedQuoted 8 lines · On 09/23/2016 02:02 PM, [email protected] wrote:
From: William Roberts <[email protected]>
_D_ALLOC_NAMLENis not very portable. Currently, the code mallocs based on_D_ALLOC_NAMLEN()and then strcpy's direntd_nameinto the buffer. Instead, just use strdup.Change-Id I5c8ca47da2c593ea2726caba5781f5e9d9d910aeSigned-off-by William Roberts <[email protected]>
Thanks, applied.
Quoted 23 lines
--- libselinux/src/booleans.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)libselinux/src/booleans.c +1
-2@@ -63,12 +63,11 @@ int security_get_boolean_names(char ***names, int *len) }for (i =0 ; i < *len; i++) { - n[i] = (char *)malloc (_D_ALLOC_NAMLEN (namelist[i])); + n[i] =strdup (namelist[i]->d_name);if (!n[i]) { rc =-1 ; goto bad_freen; } -strcpy (n[i], namelist[i]->d_name); } rc =0 ; *names = n;