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
... ...
@@ -106,6 +106,15 @@ static void log_callback_report(void *ptr, int level, const char *fmt, va_list v
106 106
     }
107 107
 }
108 108
 
109
+void init_dynload(void)
110
+{
111
+#ifdef _WIN32
112
+    /* Calling SetDllDirectory with the empty string (but not NULL) removes the
113
+     * current working directory from the DLL search path as a security pre-caution. */
114
+    SetDllDirectory("");
115
+#endif
116
+}
117
+
109 118
 static void (*program_exit)(int ret);
110 119
 
111 120
 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
  */
... ...
@@ -4118,6 +4118,8 @@ int main(int argc, char **argv)
4118 4118
     int ret;
4119 4119
     int64_t ti;
4120 4120
 
4121
+    init_dynload();
4122
+
4121 4123
     register_exit(ffmpeg_cleanup);
4122 4124
 
4123 4125
     setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
... ...
@@ -3684,6 +3684,8 @@ int main(int argc, char **argv)
3684 3684
     VideoState *is;
3685 3685
     char dummy_videodriver[] = "SDL_VIDEODRIVER=dummy";
3686 3686
 
3687
+    init_dynload();
3688
+
3687 3689
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
3688 3690
     parse_loglevel(argc, argv, options);
3689 3691
 
... ...
@@ -3142,6 +3142,8 @@ int main(int argc, char **argv)
3142 3142
     char *w_name = NULL, *w_args = NULL;
3143 3143
     int ret, i;
3144 3144
 
3145
+    init_dynload();
3146
+
3145 3147
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
3146 3148
     register_exit(ffprobe_cleanup);
3147 3149
 
... ...
@@ -3817,6 +3817,8 @@ int main(int argc, char **argv)
3817 3817
     struct sigaction sigact = { { 0 } };
3818 3818
     int ret = 0;
3819 3819
 
3820
+    init_dynload();
3821
+
3820 3822
     config.filename = av_strdup("/etc/ffserver.conf");
3821 3823
 
3822 3824
     parse_loglevel(argc, argv, options);