Commit fa9d82d
src: unify implementations of Utf8Value etc.
Unify the common code of `Utf8Value`, `TwoByteValue`, `BufferValue`
and `StringBytes::InlineDecoder` into one class. Always make the
result zero-terminated for the first three.
This fixes two problems in passing:
* When the conversion of the input value to String fails,
make the buffer zero-terminated anyway. Previously, this would
have resulted in possibly reading uninitialized data in multiple
places in the code. An instance of that problem can be reproduced
by running e.g.
`valgrind node -e 'net.isIP({ toString() { throw Error() } })'`.
* Previously, `BufferValue` copied one byte too much from the source,
possibly resulting in an out-of-bounds memory access.
This can be reproduced by running e.g.
`valgrind node -e \
'fs.openSync(Buffer.from("node".repeat(8192)), "r")'`.
Further minor changes:
* This lifts the `out()` method of `StringBytes::InlineDecoder`
to the common class so that it can be used when using the
overloaded `operator*` does not seem appropiate.
* Hopefully clearer variable names.
* Add checks to make sure the length of the data does not exceed
the allocated storage size, including the possible null terminator.
PR-URL: #6357
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>1 parent e62c42b commit fa9d82dCopy full SHA for fa9d82d
File tree
Expand file treeCollapse file tree
3 files changed
+123
-119
lines changedOpen diff view settings
Filter options
- src
Expand file treeCollapse file tree
3 files changed
+123
-119
lines changedOpen diff view settings
Collapse file
+15-29Lines changed: 15 additions & 29 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
7 | 7 | |
8 | 8 | |
9 | 9 | |
| 10 | + |
10 | 11 | |
11 | 12 | |
12 | 13 | |
13 | 14 | |
14 | 15 | |
15 | | - |
| 16 | + |
16 | 17 | |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | 18 | |
27 | 19 | |
28 | 20 | |
| ||
33 | 25 | |
34 | 26 | |
35 | 27 | |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | | - |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
46 | 40 | |
47 | 41 | |
48 | 42 | |
49 | | - |
50 | | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | | - |
57 | | - |
| 43 | + |
58 | 44 | |
59 | 45 | |
60 | 46 | |
|
Collapse file
+34-41Lines changed: 34 additions & 41 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
10 | 10 | |
11 | 11 | |
12 | 12 | |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
17 | 17 | |
18 | 18 | |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
25 | 23 | |
26 | 24 | |
27 | | - |
28 | | - |
29 | | - |
| 25 | + |
| 26 | + |
30 | 27 | |
31 | 28 | |
32 | | - |
33 | | - |
| 29 | + |
34 | 30 | |
35 | 31 | |
36 | | - |
| 32 | + |
| 33 | + |
37 | 34 | |
38 | 35 | |
39 | 36 | |
40 | | - |
41 | | - |
42 | | - |
| 37 | + |
| 38 | + |
43 | 39 | |
| 40 | + |
44 | 41 | |
45 | 42 | |
46 | 43 | |
47 | 44 | |
48 | 45 | |
49 | 46 | |
50 | | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | | - |
56 | | - |
| 47 | + |
| 48 | + |
57 | 49 | |
58 | 50 | |
59 | 51 | |
60 | | - |
61 | | - |
| 52 | + |
| 53 | + |
62 | 54 | |
63 | 55 | |
64 | | - |
65 | | - |
| 56 | + |
66 | 57 | |
67 | 58 | |
68 | 59 | |
69 | | - |
| 60 | + |
| 61 | + |
| 62 | + |
70 | 63 | |
| 64 | + |
| 65 | + |
71 | 66 | |
72 | | - |
73 | | - |
| 67 | + |
74 | 68 | |
75 | | - |
76 | | - |
77 | | - |
78 | | - |
79 | | - |
80 | | - |
81 | | - |
82 | | - |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
83 | 76 | |
84 | 77 | |
85 | 78 | |
|
Collapse file
+74-49Lines changed: 74 additions & 49 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
178 | 178 | |
179 | 179 | |
180 | 180 | |
181 | | - |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
182 | 185 | |
183 | | - |
| 186 | + |
| 187 | + |
| 188 | + |
184 | 189 | |
185 | | - |
186 | | - |
187 | | - |
| 190 | + |
| 191 | + |
188 | 192 | |
189 | 193 | |
190 | | - |
191 | | - |
192 | | - |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
193 | 198 | |
194 | | - |
195 | | - |
196 | | - |
| 199 | + |
| 200 | + |
| 201 | + |
197 | 202 | |
198 | 203 | |
199 | 204 | |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
| 205 | + |
207 | 206 | |
208 | | - |
209 | | - |
210 | | - |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
211 | 224 | |
212 | | - |
213 | | - |
214 | | - |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + |
215 | 229 | |
216 | 230 | |
217 | | - |
218 | | - |
219 | | - |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
220 | 235 | |
221 | | - |
222 | | - |
223 | | - |
| 236 | + |
| 237 | + |
| 238 | + |
224 | 239 | |
225 | | - |
226 | | - |
227 | | - |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | + |
228 | 253 | |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | + |
229 | 258 | |
230 | 259 | |
231 | | - |
232 | | - |
| 260 | + |
| 261 | + |
233 | 262 | |
234 | 263 | |
235 | | - |
| 264 | + |
236 | 265 | |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
| 266 | + |
| 267 | + |
243 | 268 | |
244 | | - |
245 | | - |
246 | | - |
| 269 | + |
| 270 | + |
| 271 | + |
| 272 | + |
247 | 273 | |
248 | | - |
249 | | - |
250 | | - |
251 | | - |
| 274 | + |
| 275 | + |
| 276 | + |
252 | 277 | |
253 | 278 | |
254 | 279 | |
|
0 commit comments