]> granicus.if.org Git - python/commitdiff
Patch #1736: Fix file name handling of _msi.FCICreate.
authorMartin v. Löwis <martin@v.loewis.de>
Tue, 12 Feb 2008 13:47:26 +0000 (13:47 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Tue, 12 Feb 2008 13:47:26 +0000 (13:47 +0000)
Misc/NEWS
PC/_msi.c

index 81eef0e633d04cdde1dfdd705d615a64f512763b..4b777367c682bf71f65658b66ff9e00a3ebb2527 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1129,6 +1129,8 @@ Library
 Extension Modules
 -----------------
 
+- Patch #1736: Fix file name handling of _msi.FCICreate.
+
 - Updated ``big5hkscs`` codec to the HKSCS revision of 2004.
 
 - #1940: make it possible to use curses.filter() before curses.initscr()
index 7d60d085dff642a23eac1f64256a03c16836fb52..dfbdf3b8698001f63e751b749c2154e70b715e17 100644 (file)
--- 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);
     }