@@ -1265,6 +1265,29 @@ static int idaapi menu_installer_cb(void *, int code, va_list)
12651265 return 0 ;
12661266}
12671267
1268+ // -------------------------------------------------------------------------
1269+ // remove current directory (empty entry) from the sys.path
1270+ static void sanitize_path ()
1271+ {
1272+ char buf[QMAXPATH];
1273+ qstrncpy (buf, Py_GetPath (), sizeof (buf));
1274+ char *ctx;
1275+ qstring newpath;
1276+ for ( char *d0 = qstrtok (buf, DELIMITER, &ctx);
1277+ d0 != NULL ;
1278+ d0 = qstrtok (NULL , DELIMITER, &ctx) )
1279+ {
1280+ if ( d0[0 ] == ' \0 ' )
1281+ // skip empty entry
1282+ continue ;
1283+
1284+ if ( !newpath.empty () )
1285+ newpath.append (DELIMITER);
1286+ newpath.append (d0);
1287+ }
1288+ PySys_SetPath (newpath.begin ());
1289+ }
1290+
12681291// -------------------------------------------------------------------------
12691292// Initialize the Python environment
12701293bool IDAPython_Init (void )
@@ -1280,7 +1303,7 @@ bool IDAPython_Init(void)
12801303 if ( !CheckScriptFiles () )
12811304 return false ;
12821305
1283- char tmp[MAXSTR+ 64 ];
1306+ char tmp[QMAXPATH ];
12841307#ifdef __LINUX__
12851308 // Export symbols from libpython to resolve imported module deps
12861309 qsnprintf (tmp, sizeof (tmp), " libpython%d.%d.so.1" ,
@@ -1319,10 +1342,9 @@ bool IDAPython_Init(void)
13191342 read_user_config_file (" python.cfg" , set_python_options, NULL );
13201343 if ( g_alert_auto_scripts )
13211344 {
1322- const char *autofn = pywraps_check_autoscripts ();
1323- if ( autofn != NULL
1345+ if ( pywraps_check_autoscripts (tmp, sizeof (tmp))
13241346 && askyn_c (0 , " HIDECANCEL\n TITLE IDAPython\n The script '%s' was found in the current directory and will be automatically executed by Python.\n\n "
1325- " Do you want to continue loading IDAPython?" , autofn) = = 0 )
1347+ " Do you want to continue loading IDAPython?" , tmp) < = 0 )
13261348 {
13271349 return false ;
13281350 }
@@ -1336,6 +1358,8 @@ bool IDAPython_Init(void)
13361358 return false ;
13371359 }
13381360
1361+ sanitize_path ();
1362+
13391363 // Enable multi-threading support
13401364 if ( !PyEval_ThreadsInitialized () )
13411365 PyEval_InitThreads ();
0 commit comments