mirror of
https://gitlab.freedesktop.org/xorg/xserver.git
synced 2026-02-14 23:50:30 +01:00
os: avoid closing null fd at Fopen
In `Fopen` function variable `iop` may store NULL as a result of `fopen`
call. In this case, if later privileges couldn't be restored (`seteuid`
call fails), further `fclose(iop)` call will cause runtime error.
This commit adds check `iop` for NULL before calling `fclose` to prevent
potential NULL pointer dereference.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/2115>
(cherry picked from commit f83807647e)
This commit is contained in:
parent
b4c5796e4b
commit
dd2255c309
1 changed files with 3 additions and 1 deletions
|
|
@ -1516,7 +1516,9 @@ Fopen(const char *file, const char *type)
|
|||
iop = fopen(file, type);
|
||||
|
||||
if (seteuid(euid) == -1) {
|
||||
fclose(iop);
|
||||
if (iop) {
|
||||
fclose(iop);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return iop;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue