Browse code

cmdutils: remove the current working directory from the DLL search path on win32

Reviewed-by: Matt Oliver <protogonoi@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 3bf142c77337814458ed8e036796934032d9837f)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Hendrik Leppkes authored on 2016/08/08 22:27:41
Showing 6 changed files
... ...
@@ -111,6 +111,15 @@ static void log_callback_report(void *ptr, int level, const char *fmt, va_list v
111 111
     }
112 112
 }
113 113
 
114
+void init_dynload(void)
115
+{
116
+#ifdef _WIN32
117
+    /* Calling SetDllDirectory with the empty string (but not NULL) removes the
118
+     * current working directory from the DLL search path as a security pre-caution. */
119
+    SetDllDirectory("");
120
+#endif
121
+}
122
+
114 123
 static void (*program_exit)(int ret);
115 124
 
116 125
 void register_exit(void (*cb)(int ret))
... ...
@@ -62,6 +62,11 @@ void register_exit(void (*cb)(int ret));
62 62
 void exit_program(int ret) av_noreturn;
63 63
 
64 64
 /**
65
+ * Initialize dynamic library loading
66
+ */
67
+void init_dynload(void);
68
+
69
+/**
65 70
  * Initialize the cmdutils option system, in particular
66 71
  * allocate the *_opts contexts.
67 72
  */
... ...
@@ -3822,6 +3822,8 @@ int main(int argc, char **argv)
3822 3822
     int ret;
3823 3823
     int64_t ti;
3824 3824
 
3825
+    init_dynload();
3826
+
3825 3827
     register_exit(ffmpeg_cleanup);
3826 3828
 
3827 3829
     setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
... ...
@@ -3659,6 +3659,8 @@ int main(int argc, char **argv)
3659 3659
     VideoState *is;
3660 3660
     char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy";
3661 3661
 
3662
+    init_dynload();
3663
+
3662 3664
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
3663 3665
     parse_loglevel(argc, argv, options);
3664 3666
 
... ...
@@ -2962,6 +2962,8 @@ int main(int argc, char **argv)
2962 2962
     char *w_name = NULL, *w_args = NULL;
2963 2963
     int ret, i;
2964 2964
 
2965
+    init_dynload();
2966
+
2965 2967
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
2966 2968
     register_exit(ffprobe_cleanup);
2967 2969
 
... ...
@@ -4724,6 +4724,8 @@ int main(int argc, char **argv)
4724 4724
     struct sigaction sigact = { { 0 } };
4725 4725
     int ret = 0;
4726 4726
 
4727
+    init_dynload();
4728
+
4727 4729
     config_filename = av_strdup("/etc/ffserver.conf");
4728 4730
 
4729 4731
     parse_loglevel(argc, argv, options);