Commit a72cc6f
committed
fix(anonymizer): truncate output files on open to prevent stale JSON
When running the anonymizer tool multiple times pointing to the same
output paths, the files were opened with O_CREATE|O_WRONLY but without
O_TRUNC. This means any previous content is kept in place and new data
is written on top. If the new output happens to be shorter than the old
one, the leftover bytes at the end produce malformed JSON that cannot
be parsed.
Added os.O_TRUNC to all three os.OpenFile calls across writer.go and
extractor.go so the file is always zeroed out before writing begins.
Also tightened the file creation mode from os.ModePerm (0777) to 0o600
so output files containing potentially sensitive trace data are not
world-readable, and included the file path in each error message to
make failures easier to diagnose.
Fixes: #8231
Signed-off-by: Sakthi Harish <sakthi.harish@edgeverve.com>1 parent e75b845 commit a72cc6f
2 files changed
+6
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
0 commit comments