Show More
@@ -9,6 +9,7 b'' | |||||
9 |
|
9 | |||
10 | #define PY_SSIZE_T_CLEAN |
|
10 | #define PY_SSIZE_T_CLEAN | |
11 | #include <Python.h> |
|
11 | #include <Python.h> | |
|
12 | #include <string.h> | |||
12 |
|
13 | |||
13 | #include "util.h" |
|
14 | #include "util.h" | |
14 |
|
15 | |||
@@ -48,12 +49,19 b' static inline Py_ssize_t _finddir(const ' | |||||
48 | return pos; |
|
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 | static int _addpath(PyObject *dirs, PyObject *path) |
|
58 | static int _addpath(PyObject *dirs, PyObject *path) | |
52 | { |
|
59 | { | |
53 | const char *cpath = PyBytes_AS_STRING(path); |
|
60 | const char *cpath = PyBytes_AS_STRING(path); | |
54 | Py_ssize_t pos = PyBytes_GET_SIZE(path); |
|
61 | Py_ssize_t pos = PyBytes_GET_SIZE(path); | |
55 | PyObject *key = NULL; |
|
62 | PyObject *key = NULL; | |
56 | int ret = -1; |
|
63 | int ret = -1; | |
|
64 | size_t num_slashes = 0; | |||
57 |
|
65 | |||
58 | /* This loop is super critical for performance. That's why we inline |
|
66 | /* This loop is super critical for performance. That's why we inline | |
59 | * access to Python structs instead of going through a supported API. |
|
67 | * access to Python structs instead of going through a supported API. | |
@@ -65,6 +73,12 b' static int _addpath(PyObject *dirs, PyOb' | |||||
65 | * unnoticed. */ |
|
73 | * unnoticed. */ | |
66 | while ((pos = _finddir(cpath, pos - 1)) != -1) { |
|
74 | while ((pos = _finddir(cpath, pos - 1)) != -1) { | |
67 | PyObject *val; |
|
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 | /* Sniff for trailing slashes, a marker of an invalid input. */ |
|
83 | /* Sniff for trailing slashes, a marker of an invalid input. */ | |
70 | if (pos > 0 && cpath[pos - 1] == '/') { |
|
84 | if (pos > 0 && cpath[pos - 1] == '/') { |
General Comments 0
You need to be logged in to leave comments.
Login now