forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitaef8948
committed
Rework refactoring of hex and encoding routines
This commit addresses some issues withc3826f8 that moved the hexdecoding routine to src/common/:- The decoding function lacked overflow checks, so when used forsecurity-related features it was an open door to out-of-bound writes ifnot carefully used that could remain undetected. Like the base64routines already in src/common/ used by SCRAM, this routine is reworkedto check for overflows by having the size of the destination bufferpassed as argument, with overflows checked before doing any writes.- The encoding routine was missing. This is moved to src/common/ andit gains the same overflow checks as the decoding part.On failure, the hex routines of src/common/ issue an error as per thediscussion done to make them usable by frontend tools, but not by sharedlibraries. Note that this is why ECPG is left out of this commit, andit still includes a duplicated logic doing hex encoding and decoding.While on it, this commit uses better variable names for the source anddestination buffers in the existing escape and base64 routines inencode.c and it makes them more robust to overflow detection. Theprevious core code issued a FATAL after doing out-of-bound writes ifgoing through the SQL functions, which would be enough to detectproblems when working on changes that impacted this area of thecode. Instead, an error is issued before doing an out-of-bound write.The hex routines were being directly called for bytea conversions andbackup manifests without such sanity checks. The current calls happento not have any problems, but careless uses of such APIs could easilylead to CVE-class bugs.Author: Bruce Momjian, Michael PaquierReviewed-by: Sehrope SarkuniDiscussion:https://postgr.es/m/20201231003557.GB22199@momjian.us1 parent0d56acf commitaef8948
File tree
10 files changed
+304
-182
lines changed- src
- backend
- replication
- utils/adt
- common
- include
- common
- utils
- tools/msvc
10 files changed
+304
-182
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | | - | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
153 | 155 | | |
154 | | - | |
155 | | - | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| |||
176 | 178 | | |
177 | 179 | | |
178 | 180 | | |
| 181 | + | |
179 | 182 | | |
180 | 183 | | |
181 | 184 | | |
| |||
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
188 | | - | |
189 | | - | |
190 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
| |||
307 | 311 | | |
308 | 312 | | |
309 | 313 | | |
310 | | - | |
| 314 | + | |
311 | 315 | | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
314 | 319 | | |
| |||
328 | 333 | | |
329 | 334 | | |
330 | 335 | | |
331 | | - | |
332 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
333 | 341 | | |
334 | 342 | | |
335 | 343 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 86 | + | |
89 | 87 | | |
90 | 88 | | |
91 | 89 | | |
| |||
129 | 127 | | |
130 | 128 | | |
131 | 129 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 130 | + | |
137 | 131 | | |
138 | 132 | | |
139 | 133 | | |
| |||
145 | 139 | | |
146 | 140 | | |
147 | 141 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
164 | 146 | | |
165 | 147 | | |
166 | 148 | | |
167 | | - | |
| 149 | + | |
168 | 150 | | |
169 | 151 | | |
170 | 152 | | |
171 | 153 | | |
172 | 154 | | |
173 | | - | |
| 155 | + | |
174 | 156 | | |
175 | 157 | | |
176 | 158 | | |
| |||
192 | 174 | | |
193 | 175 | | |
194 | 176 | | |
195 | | - | |
| 177 | + | |
196 | 178 | | |
197 | 179 | | |
198 | 180 | | |
199 | 181 | | |
200 | | - | |
| 182 | + | |
201 | 183 | | |
202 | 184 | | |
203 | 185 | | |
| |||
213 | 195 | | |
214 | 196 | | |
215 | 197 | | |
| 198 | + | |
| 199 | + | |
216 | 200 | | |
217 | 201 | | |
218 | 202 | | |
| |||
223 | 207 | | |
224 | 208 | | |
225 | 209 | | |
| 210 | + | |
| 211 | + | |
226 | 212 | | |
227 | 213 | | |
228 | 214 | | |
229 | 215 | | |
230 | 216 | | |
231 | 217 | | |
| 218 | + | |
| 219 | + | |
232 | 220 | | |
233 | 221 | | |
234 | 222 | | |
235 | 223 | | |
236 | 224 | | |
237 | 225 | | |
| 226 | + | |
238 | 227 | | |
239 | 228 | | |
240 | 229 | | |
241 | 230 | | |
242 | | - | |
| 231 | + | |
243 | 232 | | |
244 | | - | |
| 233 | + | |
245 | 234 | | |
246 | 235 | | |
247 | 236 | | |
| |||
289 | 278 | | |
290 | 279 | | |
291 | 280 | | |
| 281 | + | |
| 282 | + | |
292 | 283 | | |
293 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
294 | 288 | | |
| 289 | + | |
295 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
296 | 294 | | |
| 295 | + | |
297 | 296 | | |
298 | 297 | | |
299 | 298 | | |
| |||
305 | 304 | | |
306 | 305 | | |
307 | 306 | | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
| 356 | + | |
355 | 357 | | |
356 | 358 | | |
357 | 359 | | |
| |||
361 | 363 | | |
362 | 364 | | |
363 | 365 | | |
| 366 | + | |
| 367 | + | |
364 | 368 | | |
365 | 369 | | |
366 | 370 | | |
367 | 371 | | |
368 | 372 | | |
369 | 373 | | |
370 | 374 | | |
| 375 | + | |
| 376 | + | |
371 | 377 | | |
372 | 378 | | |
373 | 379 | | |
374 | 380 | | |
375 | 381 | | |
376 | 382 | | |
377 | 383 | | |
| 384 | + | |
378 | 385 | | |
379 | 386 | | |
380 | 387 | | |
381 | 388 | | |
382 | | - | |
| 389 | + | |
383 | 390 | | |
384 | 391 | | |
385 | 392 | | |
| |||
388 | 395 | | |
389 | 396 | | |
390 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
391 | 401 | | |
| 402 | + | |
392 | 403 | | |
393 | 404 | | |
394 | 405 | | |
| |||
400 | 411 | | |
401 | 412 | | |
402 | 413 | | |
| 414 | + | |
| 415 | + | |
403 | 416 | | |
404 | 417 | | |
405 | 418 | | |
406 | 419 | | |
407 | 420 | | |
408 | 421 | | |
| 422 | + | |
| 423 | + | |
409 | 424 | | |
410 | 425 | | |
411 | 426 | | |
| |||
423 | 438 | | |
424 | 439 | | |
425 | 440 | | |
| 441 | + | |
426 | 442 | | |
427 | 443 | | |
428 | 444 | | |
| |||
504 | 520 | | |
505 | 521 | | |
506 | 522 | | |
507 | | - | |
| 523 | + | |
508 | 524 | | |
509 | 525 | | |
510 | 526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | | - | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
307 | 308 | | |
308 | | - | |
| 309 | + | |
309 | 310 | | |
310 | | - | |
| 311 | + | |
| 312 | + | |
311 | 313 | | |
312 | 314 | | |
313 | 315 | | |
| |||
396 | 398 | | |
397 | 399 | | |
398 | 400 | | |
| 401 | + | |
| 402 | + | |
399 | 403 | | |
400 | | - | |
| 404 | + | |
401 | 405 | | |
402 | 406 | | |
403 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
404 | 410 | | |
405 | 411 | | |
406 | 412 | | |
| |||
0 commit comments
Comments
(0)