Skip to content

Commit bd07123

Browse files
committed
va: use secure_getenv instead of getenv in va_x11.c
Move the secure_getenv fallback from va.c to va_internal.h so it is available to all internal callers, and replace the plain getenv call in va_x11.c with secure_getenv. On Windows, secure_getenv is defined as getenv since there is no setuid/setgid concept. This prevents environment variables from influencing behavior in setuid/setgid programs on Linux. Signed-off-by: Carl.Zhang <carl.zhang@intel.com>
1 parent 9b1db46 commit bd07123

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

va/va.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,6 @@
5959

6060
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
6161

62-
#ifndef HAVE_SECURE_GETENV
63-
static char * secure_getenv(const char *name)
64-
{
65-
#if defined(__MINGW32__) || defined(__MINGW64__)
66-
if (getuid() == geteuid())
67-
#else
68-
if (getuid() == geteuid() && getgid() == getegid())
69-
#endif
70-
return getenv(name);
71-
else
72-
return NULL;
73-
}
74-
#endif
7562

7663
/*
7764
* read a config "env" for libva.conf or from environment setting

va/va_internal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@
2929
extern "C" {
3030
#endif
3131

32+
#ifndef HAVE_SECURE_GETENV
33+
#ifdef _WIN32
34+
/* No setuid/setgid on Windows, secure_getenv is just getenv */
35+
#define secure_getenv getenv
36+
#else
37+
static inline char * secure_getenv(const char *name)
38+
{
39+
if (getuid() == geteuid() && getgid() == getegid())
40+
return getenv(name);
41+
else
42+
return NULL;
43+
}
44+
#endif
45+
#endif
46+
3247
#define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
3348
#define CHECK_DISPLAY(dpy) if (!vaDisplayIsValid(dpy)) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
3449

va/x11/va_x11.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static VAStatus va_DisplayContextGetDriverNames(
7777
{
7878
VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
7979

80-
if (!getenv("LIBVA_DRI3_DISABLE"))
80+
if (!secure_getenv("LIBVA_DRI3_DISABLE"))
8181
vaStatus = va_DRI3_GetDriverNames(pDisplayContext, drivers, num_drivers);
8282
if (vaStatus != VA_STATUS_SUCCESS)
8383
vaStatus = va_DRI2_GetDriverNames(pDisplayContext, drivers, num_drivers);

0 commit comments

Comments
 (0)