From: Martin v. Löwis Date: Tue, 12 Feb 2008 13:48:06 +0000 (+0000) Subject: Backport of r60743: X-Git-Tag: v2.5.2c1~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cab74c8398cc83cc40feee189425274bc8722ba9;p=python Backport of r60743: Patch #1736: Fix file name handling of _msi.FCICreate. --- diff --git a/Misc/NEWS b/Misc/NEWS index 0cd7407465..ffb1771ff5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -231,6 +231,8 @@ Library Extension Modules ----------------- +- Patch #1736: Fix file name handling of _msi.FCICreate. + - Backport r59862 (issue #712900): make long regexp matches interruptable. - #1940: make it possible to use curses.filter() before curses.initscr() diff --git a/PC/_msi.c b/PC/_msi.c index f4af92af8a..de62e4c28d 100644 --- a/PC/_msi.c +++ b/PC/_msi.c @@ -180,12 +180,12 @@ static FNFCIGETOPENINFO(cb_getopeninfo) static PyObject* fcicreate(PyObject* obj, PyObject* args) { - char *cabname; + char *cabname, *p; PyObject *files; CCAB ccab; HFCI hfci; ERF erf; - int i; + Py_ssize_t i; if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files)) @@ -208,22 +208,22 @@ static PyObject* fcicreate(PyObject* obj, PyObject* args) ccab.setID = 0; ccab.szDisk[0] = '\0'; - for (i=0; cabname[i]; i++) - if (cabname[i] == '\\' || cabname[i] == '/') - break; + for (i = 0, p = cabname; *p; p = CharNext(p)) + if (*p == '\\' || *p == '/') + i = p - cabname + 1; - if (i > sizeof(ccab.szCabPath) || - strlen(cabname+i) > sizeof(ccab.szCab)) { + if (i >= sizeof(ccab.szCabPath) || + strlen(cabname+i) >= sizeof(ccab.szCab)) { PyErr_SetString(PyExc_ValueError, "path name too long"); return 0; } - if (cabname[i]) { + if (i > 0) { memcpy(ccab.szCabPath, cabname, i); ccab.szCabPath[i] = '\0'; strcpy(ccab.szCab, cabname+i); } else { - strcpy(ccab.szCabPath, "."); + strcpy(ccab.szCabPath, ".\\"); strcpy(ccab.szCab, cabname); }