GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-86179: Avoid making case-only changes when calculating realpath() … · python/cpython@a56fac8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Modules
    • getpath.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Modules/getpath.c‎

Copy file name to clipboardExpand all lines: Modules/getpath.c
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,17 @@ getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
506506
HANDLE hFile;
507507
wchar_t resolved[MAXPATHLEN+1];
508508
int len = 0, err;
509+
Py_ssize_t pathlen;
509510
PyObject *result;
510511

511-
wchar_t *path = PyUnicode_AsWideCharString(pathobj, NULL);
512+
wchar_t *path = PyUnicode_AsWideCharString(pathobj, &pathlen);
512513
if (!path) {
513514
return NULL;
514515
}
516+
if (wcslen(path) != pathlen) {
517+
PyErr_SetString(PyExc_ValueError, "path contains embedded nulls");
518+
return NULL;
519+
}
515520

516521
Py_BEGIN_ALLOW_THREADS
517522
hFile = CreateFileW(path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
@@ -535,7 +540,11 @@ getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
535540
len -= 4;
536541
}
537542
}
538-
result = PyUnicode_FromWideChar(p, len);
543+
if (CompareStringOrdinal(path, (int)pathlen, p, len, TRUE) == CSTR_EQUAL) {
544+
result = Py_NewRef(pathobj);
545+
} else {
546+
result = PyUnicode_FromWideChar(p, len);
547+
}
539548
} else {
540549
result = Py_NewRef(pathobj);
541550
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.