Repository navigation
Commit 7122298
committed
fix(hook-augment): log under the cache dir, never at a cut-off path
Why: arming the hook-augment deadline opens its breadcrumb log with
O_CREAT. The path came from raw getenv("HOME") as
"%s/.cache/codebase-memory-mcp/logs" in 1 KiB buffers with no length
check. A HOME near 1 KiB therefore created a file at the cut-off name
(".../logs/hook-augme") on every hook call, and a longer one created a
cut-off directory. The hook also ignored CBM_CACHE_DIR, which every
other cbm component honours for its cache and logs. The index skip log
had the same defect in its CBM_INDEX_LOG override: an override longer
than 1 KiB was copied in unchecked and opened "wb", which created or
truncated the file at its cut-off prefix and reported that name as the
run's logfile.
Fix: the breadcrumb log now resolves through cbm_resolve_cache_dir()
(CBM_CACHE_DIR, else HOME, else USERPROFILE, plus the default) to
<cache_dir>/logs/hook-augment-timeouts.log. Every snprintf into the
1 KiB buffers is checked, including the one for the CBM_HOOK_TIMEOUT_LOG
override. A path that does not fit means no breadcrumb, and the logs
directory is created only for a path that fits. The hook still exits 0
(it never fails the agent's hook call) and allocates nothing new. The
CBM_INDEX_LOG override gets the same check: an override that does not
fit writes no logfile and warns index.logfile_path_too_long, and the
index still completes. With a normal HOME the log stays where it was.
Proof (dev binary, synthetic roots, isolated CBM_RUNTIME_DIR, no-op
Bash payload on stdin; "created" = find over the synthetic root minus
the pre-made HOME/cache chains):
- 980-byte HOME. Before: exit 0, plus three directories and a file at
the cut-off name <HOME>/.cache/codebase-memory-mcp/logs/hook-augme
(1023 bytes). After: exit 0, nothing created.
- CBM_CACHE_DIR=<root>/cache. Before: the log landed under HOME.
After: <root>/cache/logs/hook-augment-timeouts.log.
- 1000-byte CBM_CACHE_DIR. After: exit 0, nothing created.
- Normal HOME: <HOME>/.cache/codebase-memory-mcp/logs/
hook-augment-timeouts.log before and after.
- 1096-byte CBM_INDEX_LOG via `cli index_repository`. Before: a file
at the 1023-byte cut-off name, reported as the logfile. After: status
indexed, skipped_count 1, no logfile, nothing written.
Tests: RED 3x on the unfixed code for the reasons above, green with
the fix, RED again with the fix reverted:
- cli: cli_hook_augment_log_long_home_creates_no_cut_path,
cli_hook_augment_log_honours_cache_dir, plus the positive control
cli_hook_augment_log_default_location_unchanged (green before and
after).
- index_resilience: index_long_log_override_writes_no_cut_path.
The fixtures sit under link-resolved temp roots: the kernel bounds the
expanded path, so under macOS's /tmp -> /private/tmp link a near-1 KiB
path can be neither created nor probed, and the bug stays hidden.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent 1f9b4db commit 7122298
4 files changed
Lines changed: 395 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 118 | + | |
114 | 119 | | |
115 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
116 | 125 | | |
117 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
118 | 131 | | |
119 | | - | |
120 | 132 | | |
121 | 133 | | |
122 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10280 | 10280 | | |
10281 | 10281 | | |
10282 | 10282 | | |
10283 | | - | |
| 10283 | + | |
| 10284 | + | |
| 10285 | + | |
| 10286 | + | |
| 10287 | + | |
| 10288 | + | |
| 10289 | + | |
10284 | 10290 | | |
10285 | 10291 | | |
10286 | 10292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14604 | 14604 | | |
14605 | 14605 | | |
14606 | 14606 | | |
| 14607 | + | |
| 14608 | + | |
| 14609 | + | |
| 14610 | + | |
| 14611 | + | |
| 14612 | + | |
| 14613 | + | |
| 14614 | + | |
| 14615 | + | |
| 14616 | + | |
| 14617 | + | |
| 14618 | + | |
| 14619 | + | |
| 14620 | + | |
| 14621 | + | |
| 14622 | + | |
| 14623 | + | |
| 14624 | + | |
| 14625 | + | |
| 14626 | + | |
| 14627 | + | |
| 14628 | + | |
| 14629 | + | |
| 14630 | + | |
| 14631 | + | |
| 14632 | + | |
| 14633 | + | |
| 14634 | + | |
| 14635 | + | |
| 14636 | + | |
| 14637 | + | |
| 14638 | + | |
| 14639 | + | |
| 14640 | + | |
| 14641 | + | |
| 14642 | + | |
| 14643 | + | |
| 14644 | + | |
| 14645 | + | |
| 14646 | + | |
| 14647 | + | |
| 14648 | + | |
| 14649 | + | |
| 14650 | + | |
| 14651 | + | |
| 14652 | + | |
| 14653 | + | |
| 14654 | + | |
| 14655 | + | |
| 14656 | + | |
| 14657 | + | |
| 14658 | + | |
| 14659 | + | |
| 14660 | + | |
| 14661 | + | |
| 14662 | + | |
| 14663 | + | |
| 14664 | + | |
| 14665 | + | |
| 14666 | + | |
| 14667 | + | |
| 14668 | + | |
| 14669 | + | |
| 14670 | + | |
| 14671 | + | |
| 14672 | + | |
| 14673 | + | |
| 14674 | + | |
| 14675 | + | |
| 14676 | + | |
| 14677 | + | |
| 14678 | + | |
| 14679 | + | |
| 14680 | + | |
| 14681 | + | |
| 14682 | + | |
| 14683 | + | |
| 14684 | + | |
| 14685 | + | |
| 14686 | + | |
| 14687 | + | |
| 14688 | + | |
| 14689 | + | |
| 14690 | + | |
| 14691 | + | |
| 14692 | + | |
| 14693 | + | |
| 14694 | + | |
| 14695 | + | |
| 14696 | + | |
| 14697 | + | |
| 14698 | + | |
| 14699 | + | |
| 14700 | + | |
| 14701 | + | |
| 14702 | + | |
| 14703 | + | |
| 14704 | + | |
| 14705 | + | |
| 14706 | + | |
| 14707 | + | |
| 14708 | + | |
| 14709 | + | |
| 14710 | + | |
| 14711 | + | |
| 14712 | + | |
| 14713 | + | |
| 14714 | + | |
| 14715 | + | |
| 14716 | + | |
| 14717 | + | |
| 14718 | + | |
| 14719 | + | |
| 14720 | + | |
| 14721 | + | |
| 14722 | + | |
| 14723 | + | |
| 14724 | + | |
| 14725 | + | |
| 14726 | + | |
| 14727 | + | |
| 14728 | + | |
| 14729 | + | |
| 14730 | + | |
| 14731 | + | |
| 14732 | + | |
| 14733 | + | |
| 14734 | + | |
| 14735 | + | |
| 14736 | + | |
| 14737 | + | |
| 14738 | + | |
| 14739 | + | |
| 14740 | + | |
| 14741 | + | |
| 14742 | + | |
| 14743 | + | |
| 14744 | + | |
| 14745 | + | |
| 14746 | + | |
| 14747 | + | |
| 14748 | + | |
| 14749 | + | |
| 14750 | + | |
| 14751 | + | |
| 14752 | + | |
| 14753 | + | |
| 14754 | + | |
| 14755 | + | |
| 14756 | + | |
| 14757 | + | |
| 14758 | + | |
| 14759 | + | |
| 14760 | + | |
| 14761 | + | |
| 14762 | + | |
| 14763 | + | |
| 14764 | + | |
| 14765 | + | |
| 14766 | + | |
| 14767 | + | |
| 14768 | + | |
| 14769 | + | |
| 14770 | + | |
| 14771 | + | |
| 14772 | + | |
| 14773 | + | |
| 14774 | + | |
| 14775 | + | |
| 14776 | + | |
| 14777 | + | |
| 14778 | + | |
| 14779 | + | |
| 14780 | + | |
| 14781 | + | |
| 14782 | + | |
| 14783 | + | |
| 14784 | + | |
| 14785 | + | |
| 14786 | + | |
| 14787 | + | |
| 14788 | + | |
| 14789 | + | |
| 14790 | + | |
| 14791 | + | |
| 14792 | + | |
| 14793 | + | |
| 14794 | + | |
| 14795 | + | |
| 14796 | + | |
| 14797 | + | |
| 14798 | + | |
| 14799 | + | |
| 14800 | + | |
| 14801 | + | |
| 14802 | + | |
| 14803 | + | |
| 14804 | + | |
| 14805 | + | |
| 14806 | + | |
| 14807 | + | |
| 14808 | + | |
| 14809 | + | |
| 14810 | + | |
| 14811 | + | |
| 14812 | + | |
| 14813 | + | |
| 14814 | + | |
| 14815 | + | |
| 14816 | + | |
| 14817 | + | |
| 14818 | + | |
| 14819 | + | |
| 14820 | + | |
| 14821 | + | |
| 14822 | + | |
| 14823 | + | |
| 14824 | + | |
| 14825 | + | |
| 14826 | + | |
| 14827 | + | |
| 14828 | + | |
| 14829 | + | |
| 14830 | + | |
| 14831 | + | |
| 14832 | + | |
| 14833 | + | |
| 14834 | + | |
| 14835 | + | |
| 14836 | + | |
| 14837 | + | |
| 14838 | + | |
| 14839 | + | |
| 14840 | + | |
| 14841 | + | |
| 14842 | + | |
| 14843 | + | |
| 14844 | + | |
| 14845 | + | |
| 14846 | + | |
| 14847 | + | |
| 14848 | + | |
| 14849 | + | |
| 14850 | + | |
| 14851 | + | |
| 14852 | + | |
| 14853 | + | |
| 14854 | + | |
| 14855 | + | |
| 14856 | + | |
| 14857 | + | |
| 14858 | + | |
| 14859 | + | |
| 14860 | + | |
14607 | 14861 | | |
14608 | 14862 | | |
14609 | 14863 | | |
| |||
16596 | 16850 | | |
16597 | 16851 | | |
16598 | 16852 | | |
| 16853 | + | |
| 16854 | + | |
| 16855 | + | |
16599 | 16856 | | |
16600 | 16857 | | |
16601 | 16858 | | |
| |||
0 commit comments