57
57
#define CHECK_MAXIMUM (s , ctx , var ) if (!va_checkMaximum(dpy, ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
58
58
#define CHECK_STRING (s , ctx , var ) if (!va_checkString(dpy, ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
59
59
60
+ #ifndef HAVE_SECURE_GETENV
61
+ static char * secure_getenv (const char * name )
62
+ {
63
+ #if defined(__MINGW32__ ) || defined(__MINGW64__ )
64
+ if (getuid () == geteuid ())
65
+ #else
66
+ if (getuid () == geteuid () && getgid () == getegid ())
67
+ #endif
68
+ return getenv (name );
69
+ else
70
+ return NULL ;
71
+ }
72
+ #endif
73
+
60
74
/*
61
75
* read a config "env" for libva.conf or from environment setting
62
76
* libva.conf has higher priority
@@ -97,7 +111,7 @@ int va_parseConfig(char *env, char *env_value)
97
111
fclose (fp );
98
112
99
113
/* no setting in config file, use env setting */
100
- value = getenv (env );
114
+ value = secure_getenv (env );
101
115
if (value ) {
102
116
if (env_value ) {
103
117
strncpy (env_value , value , 1024 );
@@ -348,7 +362,7 @@ static VAStatus va_getDriverNumCandidates(VADisplay dpy, int *num_candidates)
348
362
VADriverContextP ctx ;
349
363
350
364
ctx = CTX (dpy );
351
- driver_name_env = getenv ("LIBVA_DRIVER_NAME" );
365
+ driver_name_env = secure_getenv ("LIBVA_DRIVER_NAME" );
352
366
353
367
if (pDisplayContext -> vaGetNumCandidates )
354
368
vaStatus = pDisplayContext -> vaGetNumCandidates (pDisplayContext , num_candidates );
@@ -374,7 +388,7 @@ static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int c
374
388
else
375
389
status = VA_STATUS_ERROR_INVALID_PARAMETER ;
376
390
}
377
- driver_name_env = getenv ("LIBVA_DRIVER_NAME" );
391
+ driver_name_env = secure_getenv ("LIBVA_DRIVER_NAME" );
378
392
/*if user set driver name by vaSetDriverName */
379
393
if (ctx -> override_driver_name ) {
380
394
if (* driver_name )
@@ -424,7 +438,7 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
424
438
425
439
if (geteuid () == getuid ())
426
440
/* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
427
- search_path = getenv ("LIBVA_DRIVERS_PATH" );
441
+ search_path = secure_getenv ("LIBVA_DRIVERS_PATH" );
428
442
if (!search_path )
429
443
search_path = VA_DRIVERS_PATH ;
430
444
0 commit comments