Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 0282e67

Browse files
author
skochinsky@gmail.com
committed
IDAPython 1.5.4
- fix for Python autorun script vulnerability reported by Greg MacManus - remove current directory from sys.path during initialization
1 parent 06f0ff1 commit 0282e67

6 files changed

Lines changed: 78 additions & 20 deletions

File tree

CHANGES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Please see http://code.google.com/p/idapython/source/list for a detailed list of changes.
22

33

4+
Changes from version 1.5.3 to 1.5.4
5+
------------------------------------
6+
- fix for Python autorun script vulnerability reported by Greg MacManus
7+
- remove current directory from sys.path during initialization
8+
- added PyWraps sources. This will facilitate deployment, development and
9+
debugging of IDAPython additions
10+
- bugfix: op_t.is_reg() was buggy
11+
- bugfix: build.py was putting duplicate files into the .zip
12+
- bugfix: added back wrapped version of get_ascii_contents()
13+
414
Changes from version 1.5.2 to 1.5.3
515
------------------------------------
616
- IDA Pro 6.2 support

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# IDAPython version
3737
VERSION_MAJOR = 1
3838
VERSION_MINOR = 5
39-
VERSION_PATCH = 3
39+
VERSION_PATCH = 4
4040

4141
# Determine Python version
4242
PYTHON_MAJOR_VERSION = int(platform.python_version()[0])

python.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
12701293
bool 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\nTITLE IDAPython\nThe 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();

pywraps.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ bool pywraps_nw_notify(int slot, ...);
227227
bool pywraps_nw_init();
228228

229229
//---------------------------------------------------------------------------
230-
const char *pywraps_check_autoscripts();
230+
bool pywraps_check_autoscripts(char *buf, size_t bufsize);
231231

232232
// [De]Initializes PyWraps
233233
bool init_pywraps();

pywraps/py_idaapi.hpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,28 +94,40 @@ struct py_timer_ctx_t
9494
};
9595

9696
//------------------------------------------------------------------------
97-
const char *pywraps_check_autoscripts()
97+
bool pywraps_check_autoscripts(char *buf, size_t bufsize)
9898
{
99-
static const char *exts[] = {"py", "pyw", "pyc", "pyo"};
99+
static const char *const exts[] =
100+
{
101+
"py",
102+
"pyc",
103+
"pyd",
104+
"pyo",
105+
"pyw",
106+
};
100107

101-
static const char *fns[] =
108+
static const char *const fns[] =
102109
{
103110
"swig_runtime_data" SWIG_RUNTIME_VERSION,
104111
"sitecustomize",
105112
"usercustomize"
106113
};
107114

108-
for (size_t ifn=0; ifn < qnumber(fns); ++ifn )
115+
for ( size_t ifn=0; ifn < qnumber(fns); ++ifn )
109116
{
110117
for ( size_t iext=0; iext < qnumber(exts); ++iext )
111118
{
112119
static char fn[QMAXPATH];
113-
qsnprintf(fn, sizeof(fn), "%s.%s", fns[ifn], exts[iext]);
120+
qsnprintf(buf, bufsize, "%s.%s", fns[ifn], exts[iext]);
114121
if ( qfileexist(fn) )
115-
return fn;
122+
return true;
123+
if ( qfileexist(fns[ifn]) )
124+
{
125+
qstrncpy(buf, fns[ifn], bufsize);
126+
return true;
127+
}
116128
}
117129
}
118-
return NULL;
130+
return false;
119131
}
120132

121133
//------------------------------------------------------------------------

swig/idaapi.i

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,28 +1289,40 @@ struct py_timer_ctx_t
12891289
};
12901290

12911291
//------------------------------------------------------------------------
1292-
const char *pywraps_check_autoscripts()
1292+
bool pywraps_check_autoscripts(char *buf, size_t bufsize)
12931293
{
1294-
static const char *exts[] = {"py", "pyw", "pyc", "pyo"};
1294+
static const char *const exts[] =
1295+
{
1296+
"py",
1297+
"pyc",
1298+
"pyd",
1299+
"pyo",
1300+
"pyw",
1301+
};
12951302

1296-
static const char *fns[] =
1303+
static const char *const fns[] =
12971304
{
12981305
"swig_runtime_data" SWIG_RUNTIME_VERSION,
12991306
"sitecustomize",
13001307
"usercustomize"
13011308
};
13021309

1303-
for (size_t ifn=0; ifn < qnumber(fns); ++ifn )
1310+
for ( size_t ifn=0; ifn < qnumber(fns); ++ifn )
13041311
{
13051312
for ( size_t iext=0; iext < qnumber(exts); ++iext )
13061313
{
13071314
static char fn[QMAXPATH];
1308-
qsnprintf(fn, sizeof(fn), "%s.%s", fns[ifn], exts[iext]);
1315+
qsnprintf(buf, bufsize, "%s.%s", fns[ifn], exts[iext]);
13091316
if ( qfileexist(fn) )
1310-
return fn;
1317+
return true;
1318+
if ( qfileexist(fns[ifn]) )
1319+
{
1320+
qstrncpy(buf, fns[ifn], bufsize);
1321+
return true;
1322+
}
13111323
}
13121324
}
1313-
return NULL;
1325+
return false;
13141326
}
13151327

13161328
//------------------------------------------------------------------------

0 commit comments

Comments
 (0)