Dry-run mode writes to /etc/apt/sources.list on the legacy Debian/Ubuntu source-list path
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Đọc src/recipe/os/APT/common.h quanh ensure_debian_or_ubuntu_old_sourcelist() và so sánh thao tác ghi của hàm với đường dẫn hỗ trợ dry-run trong src/framework/OS.c. Kiểm tra các vị trí gọi của Debian và Ubuntu được liệt kê trong issue, sau đó chạy các bài kiểm thử liên quan của dự án hoặc tái hiện bằng chsrc set -dry debian khi tệp danh sách nguồn cũ không tồn tại. Hoàn tất khi dry-run không tạo /etc/apt/sources.list và hàm giữ nguyên hành vi trả về đã nêu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
chsrc set -dry writes to /etc/apt/sources.list on Debian/Ubuntu when the file does not exist. Dry-run mode is not fully honored on this code path.
Problem
ensure_debian_or_ubuntu_old_sourcelist() in src/recipe/os/APT/common.h generates a source-list template and writes it with a raw fopen/fwrite, without checking in_dry_run_mode():
src/recipe/os/APT/common.h:116-118
FILE *f = fopen (OS_Apt_SourceList, "w");
fwrite (makeup, strlen (makeup), 1, f);
fclose (f);
This bypasses chsrc_overwrite_file() (src/framework/OS.c:836), which is where the dry-run guard normally lives.
Call sites:
src/recipe/os/APT/Debian.c:127src/recipe/os/APT/Debian.c:145(re-invoked after CDROM source removal)src/recipe/os/APT/Ubuntu.c:127
Trigger
The function is reached only on the old-format (non-DEB822) path. os_debian_setsrc() returns early when a DEB822 file exists (src/recipe/os/APT/Debian.c:117-122), so the bug does not trigger on a stock Debian 12 / Ubuntu 24.04 installation.
It triggers when:
- the system still uses the legacy
/etc/apt/sources.list(pre-Debian-12 / pre-Ubuntu-24.04 layout), and the file is absent, or - a minimal container image ships neither
debian.sourcesnorsources.list
Reproduction
On a Debian-family system where /etc/apt/sources.list does not exist:
sudo chsrc set -dry debian
Expected: prints the command it would run, writes nothing.
Actual: /etc/apt/sources.list is created on disk.
Verify:
ls -l /etc/apt/sources.list # file now exists, despite -dry
Why this matters
Dry-run mode is the recommended way to preview a change on a system you care about — and it is the only isolation mechanism available to non-root users. This path silently writes to a system-wide config file, which is exactly what -dry is supposed to prevent.
It is most surprising inside containers and chroots, where an isolated -dry run is the normal way to test a configuration change before applying it.
Suggested fix
Route the write through chsrc_overwrite_file() (or add an explicit in_dry_run_mode() check before the fopen), so the guard applies consistently:
if (in_dry_run_mode ())
return false;
FILE *f = fopen (OS_Apt_SourceList, "w");
...
Note that this function returns bool (whether the file existed). Under -dry it should keep returning false so the caller continues down the existing path without acting on a file that was never written.
Related
- The DEB822 path (
os_debian_setsrc_for_deb822,src/recipe/os/APT/Debian.c:83) goes throughchsrc_run(), which does honor-dry. The inconsistency between the two branches is what makes this easy to miss. - Reference: upstream issue #185 introduced this function for systems with no existing source list, but did not account for dry-run mode.
Environment
- chsrc: v0.2.7.2 (
0bcc4c2) - Reproduced by code inspection; the logic path is unconditional once the old-format branch is taken
- Ngôn ngữ chính
- C
- Star
- 6.9k
- Fork
- 285
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của RubyMetric/chsrc
-
[arch] 多次 chsrc set arch 后 mirrorlist 累积旧 Server 行,upstream 官方源地址无效Có thể làm lại được @yayoinoyume đã nhận 32 ngày trước và không có pull request nào đang mở. Đang mởLinux os_dish 源
RubyMetric/chsrc#393 · 2 bình luận · 2 reaction · 1 người được giao ·
-
`ls` 命令呈现 "可用源" 的界面有改进空间Có thể làm lại được @ccmywish đã nhận 33 ngày trước và không có pull request nào đang mở. Đang mở改善加强
RubyMetric/chsrc#389 · 6 bình luận · 1 người được giao ·
-
对 `Omarchy`(基于 Arch Linux 的发行版)的支持Có thể làm lại được @yayoinoyume đã nhận 33 ngày trước và không có pull request nào đang mở. Đang mởLinux os_dish
RubyMetric/chsrc#387 · 8 bình luận · 1 reaction · 1 người được giao ·
-
`curl` 测速 段错误 (核心已转储)Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
RubyMetric/chsrc#386 · 6 bình luận ·
-
对 `sources dish` 贡献者的展示Có thể làm lại được @ccmywish đã nhận 47 ngày trước và không có pull request nào đang mở. Đang mở改善加强
RubyMetric/chsrc#384 · 5 bình luận · 1 người được giao ·
Tất cả issue của RubyMetric/chsrc
Issue tương tự
-
Policy query leaks host primary block (BSL_PrimaryBlock_deinit skipped) on two early-exit pathsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NASA-AMMOS/BSL#355 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
#242 leftovers: dated narrative and shas in the social-features test planCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
EchoTools/nevr-runtime#264 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/docdb kind/bug priority/medium status/awaiting-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
yugabyte/yugabyte-db#34873 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[sqlcipher] update to 4.19.0Đang mởcategory:port-update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày