qsap: Add NULL check for getpwnam and getgrnam.
Add appropriate checks to avoid NULL pointer dereferencing. Change-Id: I0961a8e55fea055ee731e20ae28c833c54c32e67 CRs-Fixed: 2263188
This commit is contained in:
parent
e4263cecd2
commit
bfad727b06
1 changed files with 13 additions and 3 deletions
|
@ -603,6 +603,8 @@ int wigig_ensure_entropy_file_exists()
|
|||
{
|
||||
int ret;
|
||||
int destfd;
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
|
||||
ret = access(WIGIG_ENTROPY_FILE, R_OK|W_OK);
|
||||
if ((ret == 0) || (errno == EACCES)) {
|
||||
|
@ -634,9 +636,17 @@ int wigig_ensure_entropy_file_exists()
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (chown(WIGIG_ENTROPY_FILE, getpwnam("system")->pw_uid, getgrnam("wifi")->gr_gid) < 0) {
|
||||
ALOGE("Error changing group ownership of %s to %d: %s",
|
||||
WIGIG_ENTROPY_FILE, getgrnam("wifi")->gr_gid, strerror(errno));
|
||||
pw = getpwnam("system");
|
||||
gr = getgrnam("wifi");
|
||||
if (pw && gr) {
|
||||
if (chown(WIGIG_ENTROPY_FILE, pw->pw_uid, gr->gr_gid) < 0) {
|
||||
ALOGE("Error changing group ownership of %s to %d: %s",
|
||||
WIGIG_ENTROPY_FILE, gr->gr_gid, strerror(errno));
|
||||
unlink(WIGIG_ENTROPY_FILE);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ALOGE("Cannot get pw_uid or gr_gid : %s", strerror(errno));
|
||||
unlink(WIGIG_ENTROPY_FILE);
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue