Commit 46cb56f
committed
backup: close S3 KEYMAP fd + use openSidecarFile (PR #718, round 7)
Codex round 9 raised two issues on commit ab38eb0:
1. P1: closeBucketKeymap leaked file descriptors. recordKeymap
stored only the *KeymapWriter; closeBucketKeymap called
KeymapWriter.Close() which flushes the bufio buffer but does
NOT close the underlying *os.File. A dump producing keymaps
for many buckets accumulated descriptors until EMFILE, after
which subsequent bucket flushes failed and the dump output
was incomplete. Track the *os.File on s3BucketState and
close it from closeBucketKeymap alongside the KeymapWriter
flush.
2. P2: recordKeymap used os.Create for KEYMAP.jsonl, which
follows symlinks and clobbers hard links. The redis encoder
already routes through openSidecarFile for the same kind of
sidecar; mirror that path so a stale prior run (or local
adversary) cannot turn a missing KEYMAP into an
arbitrary-write primitive against /etc/passwd or similar.
Test: TestS3_KeymapRefusesSymlinkAtFinalize pre-creates
KEYMAP.jsonl as a symlink to a bait file, drives a meta-suffix
rename (so recordKeymap fires), and asserts both that the
finalize returns the symlink-refusal error and that the bait
file is untouched.1 parent ab38eb0 commit 46cb56f
2 files changed
Lines changed: 64 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
| |||
564 | 570 | | |
565 | 571 | | |
566 | 572 | | |
567 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
568 | 578 | | |
569 | 579 | | |
570 | 580 | | |
571 | 581 | | |
572 | | - | |
573 | | - | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
574 | 589 | | |
575 | 590 | | |
576 | 591 | | |
577 | 592 | | |
578 | | - | |
| 593 | + | |
579 | 594 | | |
580 | 595 | | |
581 | 596 | | |
| |||
744 | 759 | | |
745 | 760 | | |
746 | 761 | | |
747 | | - | |
748 | | - | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
749 | 768 | | |
750 | | - | |
| 769 | + | |
751 | 770 | | |
752 | 771 | | |
| 772 | + | |
753 | 773 | | |
754 | 774 | | |
755 | 775 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
284 | 285 | | |
285 | 286 | | |
286 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
287 | 322 | | |
288 | 323 | | |
289 | 324 | | |
| |||
0 commit comments