Commit 786ecbd
Introduce pg_parse_lsn() to validate LSN command-line options
pg_waldump (--start/--end), pg_recvlogical (--startpos/--endpos), and
pg_receivewal (--endpos) parsed user-supplied WAL locations with
sscanf("%X/%08X"), which accepts several forms of input that the
backend's pg_lsn type rejects, and in each case proceeds with a
location the user did not specify:
* A first component wider than 32 bits overflows its uint32 argument,
which is undefined behavior per C99 7.19.6.2p10; glibc keeps the
low-order 32 bits, so --startpos 123456789/0 runs with 23456789/0.
A component wider than 64 bits additionally saturates to ULONG_MAX
before the truncation.
* sscanf() succeeds without consuming the whole string, so trailing
characters are silently ignored: 0/123456789 is read as 0/12345678
and 1/2/3 as 1/2.
* The %X conversion follows strtoul()'s rules, so leading whitespace,
signs, and "0x" prefixes are accepted: --endpos -1/0 runs with
FFFFFFFF/0.
Add pg_parse_lsn() to src/common, following the backend's
pg_lsn_in_safe(): one to eight hex digits, a slash, one to eight hex
digits, and nothing else. Use it for the three options above. Inputs
the server accepts as pg_lsn are accepted unchanged; everything else
now fails with each tool's existing "invalid WAL location" or "could
not parse start/end position" error, so the error texts are unchanged.
The other frontend parsers of the same shape (in pg_basebackup,
pg_rewind, pg_combinebackup, and parse_manifest.c) read
server-generated strings rather than command-line input and are left
alone, as is the backend's pg_lsn_in_safe() itself.
Add regression tests for the previously-accepted forms.
Bug: #19598
Reported-by: Michael Malis <malis@pgrust.com>
Suggested-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/19598-aa67c8f4331611b4@postgresql.org1 parent db0c984 commit 786ecbd
10 files changed
Lines changed: 128 additions & 17 deletions
File tree
- src
- bin
- pg_basebackup
- t
- pg_waldump
- t
- common
- include/common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
651 | 652 | | |
652 | 653 | | |
653 | 654 | | |
654 | | - | |
655 | | - | |
656 | 655 | | |
657 | 656 | | |
658 | 657 | | |
| |||
689 | 688 | | |
690 | 689 | | |
691 | 690 | | |
692 | | - | |
| 691 | + | |
693 | 692 | | |
694 | | - | |
695 | 693 | | |
696 | 694 | | |
697 | 695 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
729 | 730 | | |
730 | 731 | | |
731 | 732 | | |
732 | | - | |
733 | | - | |
734 | 733 | | |
735 | 734 | | |
736 | 735 | | |
| |||
801 | 800 | | |
802 | 801 | | |
803 | 802 | | |
804 | | - | |
| 803 | + | |
805 | 804 | | |
806 | | - | |
807 | 805 | | |
808 | 806 | | |
809 | | - | |
| 807 | + | |
810 | 808 | | |
811 | | - | |
812 | 809 | | |
813 | 810 | | |
814 | 811 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
27 | 35 | | |
28 | 36 | | |
29 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
46 | 62 | | |
47 | 63 | | |
48 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
928 | 929 | | |
929 | 930 | | |
930 | 931 | | |
931 | | - | |
932 | | - | |
933 | 932 | | |
934 | 933 | | |
935 | 934 | | |
| |||
1047 | 1046 | | |
1048 | 1047 | | |
1049 | 1048 | | |
1050 | | - | |
| 1049 | + | |
1051 | 1050 | | |
1052 | 1051 | | |
1053 | 1052 | | |
1054 | 1053 | | |
1055 | 1054 | | |
1056 | | - | |
1057 | 1055 | | |
1058 | 1056 | | |
1059 | 1057 | | |
| |||
1145 | 1143 | | |
1146 | 1144 | | |
1147 | 1145 | | |
1148 | | - | |
| 1146 | + | |
1149 | 1147 | | |
1150 | 1148 | | |
1151 | 1149 | | |
1152 | 1150 | | |
1153 | 1151 | | |
1154 | | - | |
1155 | | - | |
1156 | 1152 | | |
1157 | 1153 | | |
1158 | 1154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments