Show More
@@ -9,6 +9,7 b'' | |||
|
9 | 9 | |
|
10 | 10 | #define PY_SSIZE_T_CLEAN |
|
11 | 11 | #include <Python.h> |
|
12 | #include <string.h> | |
|
12 | 13 | |
|
13 | 14 | #include "util.h" |
|
14 | 15 | |
@@ -48,12 +49,19 b' static inline Py_ssize_t _finddir(const ' | |||
|
48 | 49 | return pos; |
|
49 | 50 | } |
|
50 | 51 | |
|
52 | /* Mercurial will fail to run on directory hierarchies deeper than | |
|
53 | * this constant, so we should try and keep this constant as big as | |
|
54 | * possible. | |
|
55 | */ | |
|
56 | #define MAX_DIRS_DEPTH 2048 | |
|
57 | ||
|
51 | 58 | static int _addpath(PyObject *dirs, PyObject *path) |
|
52 | 59 | { |
|
53 | 60 | const char *cpath = PyBytes_AS_STRING(path); |
|
54 | 61 | Py_ssize_t pos = PyBytes_GET_SIZE(path); |
|
55 | 62 | PyObject *key = NULL; |
|
56 | 63 | int ret = -1; |
|
64 | size_t num_slashes = 0; | |
|
57 | 65 | |
|
58 | 66 | /* This loop is super critical for performance. That's why we inline |
|
59 | 67 | * access to Python structs instead of going through a supported API. |
@@ -65,6 +73,12 b' static int _addpath(PyObject *dirs, PyOb' | |||
|
65 | 73 | * unnoticed. */ |
|
66 | 74 | while ((pos = _finddir(cpath, pos - 1)) != -1) { |
|
67 | 75 | PyObject *val; |
|
76 | ++num_slashes; | |
|
77 | if (num_slashes > MAX_DIRS_DEPTH) { | |
|
78 | PyErr_SetString(PyExc_ValueError, | |
|
79 | "Directory hierarchy too deep."); | |
|
80 | goto bail; | |
|
81 | } | |
|
68 | 82 | |
|
69 | 83 | /* Sniff for trailing slashes, a marker of an invalid input. */ |
|
70 | 84 | if (pos > 0 && cpath[pos - 1] == '/') { |
General Comments 0
You need to be logged in to leave comments.
Login now