Show More
@@ -77,7 +77,7 b' static PyObject *unhexlify(const char *s' | |||
|
77 | 77 | static PyObject *parse_manifest(PyObject *self, PyObject *args) |
|
78 | 78 | { |
|
79 | 79 | PyObject *mfdict, *fdict; |
|
80 |
char *str, * |
|
|
80 | char *str, *start, *end; | |
|
81 | 81 | int len; |
|
82 | 82 | |
|
83 | 83 | if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest", |
@@ -86,30 +86,34 b' static PyObject *parse_manifest(PyObject' | |||
|
86 | 86 | &str, &len)) |
|
87 | 87 | goto quit; |
|
88 | 88 | |
|
89 | for (start = cur = str, zero = NULL; cur < str + len; cur++) { | |
|
89 | start = str; | |
|
90 | end = str + len; | |
|
91 | while (start < end) { | |
|
90 | 92 | PyObject *file = NULL, *node = NULL; |
|
91 | 93 | PyObject *flags = NULL; |
|
94 | char *zero = NULL, *newline = NULL; | |
|
92 | 95 | ptrdiff_t nlen; |
|
93 | 96 | |
|
94 | if (!*cur) { | |
|
95 | zero = cur; | |
|
96 | continue; | |
|
97 | } | |
|
98 | else if (*cur != '\n') | |
|
99 | continue; | |
|
100 | ||
|
97 | zero = memchr(start, '\0', end - start); | |
|
101 | 98 | if (!zero) { |
|
102 | 99 | PyErr_SetString(PyExc_ValueError, |
|
103 | 100 | "manifest entry has no separator"); |
|
104 | 101 | goto quit; |
|
105 | 102 | } |
|
106 | 103 | |
|
104 | newline = memchr(zero + 1, '\n', end - (zero + 1)); | |
|
105 | if (!newline) { | |
|
106 | PyErr_SetString(PyExc_ValueError, | |
|
107 | "manifest contains trailing garbage"); | |
|
108 | goto quit; | |
|
109 | } | |
|
110 | ||
|
107 | 111 | file = PyBytes_FromStringAndSize(start, zero - start); |
|
108 | 112 | |
|
109 | 113 | if (!file) |
|
110 | 114 | goto bail; |
|
111 | 115 | |
|
112 |
nlen = |
|
|
116 | nlen = newline - zero - 1; | |
|
113 | 117 | |
|
114 | 118 | node = unhexlify(zero + 1, nlen > 40 ? 40 : (int)nlen); |
|
115 | 119 | if (!node) |
@@ -128,8 +132,7 b' static PyObject *parse_manifest(PyObject' | |||
|
128 | 132 | if (PyDict_SetItem(mfdict, file, node) == -1) |
|
129 | 133 | goto bail; |
|
130 | 134 | |
|
131 |
start = |
|
|
132 | zero = NULL; | |
|
135 | start = newline + 1; | |
|
133 | 136 | |
|
134 | 137 | Py_XDECREF(flags); |
|
135 | 138 | Py_XDECREF(node); |
@@ -142,12 +145,6 b' static PyObject *parse_manifest(PyObject' | |||
|
142 | 145 | goto quit; |
|
143 | 146 | } |
|
144 | 147 | |
|
145 | if (len > 0 && *(cur - 1) != '\n') { | |
|
146 | PyErr_SetString(PyExc_ValueError, | |
|
147 | "manifest contains trailing garbage"); | |
|
148 | goto quit; | |
|
149 | } | |
|
150 | ||
|
151 | 148 | Py_INCREF(Py_None); |
|
152 | 149 | return Py_None; |
|
153 | 150 | quit: |
General Comments 0
You need to be logged in to leave comments.
Login now