Repository navigation
Commit c532da6
committed
PYCBC-1816: Fix NULL-derefs and reference leaks in legacy tracing
* NULL-check the set_attribute lookup in the deprecated_request_span
constructor. It was stored unchecked, so both add_tag overloads
could pass a NULL callable to PyObject_Call and the destructor could
Py_DECREF(NULL)
* Allow pyObj_span_ to be NULL and tolerate it in every override. A
span constructor cannot report a failure: spans are built from the
void-returning extract_legacy_span_field helpers in utils.hxx and
from start_span, which C++ core calls on its own IO threads, so a
throw has nowhere to go. Failures now degrade the span to a no-op
and are reported with PyErr_WriteUnraisable, matching the pattern
already used in logger.hxx and utils.hxx add_field
* DECREF the set_attribute and finish call results. Both were new
references that were discarded, leaking one object per tagged
operation and one per span end
* Route both add_tag overloads through a call_set_attribute helper that
NULL-checks the Py_BuildValue result before calling, rather than
passing an unchecked args tuple
* NULL-check the finish lookup in end() before PyObject_CallObject, so
a span without that attribute no longer dereferences NULL and then
hits Py_DECREF(NULL)
* NULL-check PyTuple_New, PyDict_New, PyUnicode_FromString and
PyDict_SetItemString in start_span, and stop handing an unchecked
PyObject_Call result to the span constructor, which Py_INCREFs it.
A user tracer whose start_span raises previously crashed here; the
object it returns is never validated on the Python side
* Check the dynamic_pointer_cast result for the parent span in
start_span. A parent that is not a deprecated_request_span gave a
null shared_ptr that was immediately dereferenced; such a parent now
starts a top-level span instead of failing the operation
* Report the failure with PyErr_WriteUnraisable instead of returning
into C++ core with an exception still set, which would have surfaced
as an unrelated error on the next C-API call
* Delete the pyObj_get_context_ member, which was never initialized or
read
Change-Id: I779fcb0174102a3fc1dd74f79cc12e2b2c6642ca
Reviewed-on: https://review.couchbase.org/c/couchbase-python-client/+/249624
Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Tested-by: Build Bot <build@couchbase.com>1 parent d11df43 commit c532da6
1 file changed
Lines changed: 88 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
| |||
49 | 57 | | |
50 | 58 | | |
51 | 59 | | |
52 | | - | |
53 | | - | |
| 60 | + | |
| 61 | + | |
54 | 62 | | |
55 | 63 | | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
59 | 67 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | | - | |
70 | | - | |
71 | | - | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
81 | 95 | | |
82 | 96 | | |
83 | 97 | | |
| |||
87 | 101 | | |
88 | 102 | | |
89 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
90 | 123 | | |
91 | | - | |
92 | | - | |
| 124 | + | |
93 | 125 | | |
94 | 126 | | |
95 | 127 | | |
| |||
130 | 162 | | |
131 | 163 | | |
132 | 164 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 165 | + | |
143 | 166 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 167 | + | |
148 | 168 | | |
149 | 169 | | |
150 | 170 | | |
| |||
158 | 178 | | |
159 | 179 | | |
160 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
161 | 221 | | |
162 | 222 | | |
163 | 223 | | |
| |||
0 commit comments