Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Dry-run mode writes to /etc/apt/sources.list on the legacy Debian/Ubuntu source-list path

未关闭 适合新手
#396 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c, linux
领域
cli, devtools

调研方向

阅读 src/recipe/os/APT/common.h 中 ensure_debian_or_ubuntu_old_sourcelist() 附近的代码,并将其写入操作与 src/framework/OS.c 中支持 dry-run 的路径进行比较。检查 issue 中列出的 Debian 和 Ubuntu 调用点,然后运行项目相关测试,或者在旧的源列表文件不存在时使用 chsrc set -dry debian 复现问题。完成标准是 dry-run 不会创建 /etc/apt/sources.list,且函数保留所述的返回行为。

由索引模型根据 Issue 内容生成。

描述

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:127
  • src/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.sources nor sources.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 through chsrc_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
主要语言
C
星标
6.9k
派生
285
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

RubyMetric/chsrc 的其他 Issue

查看 RubyMetric/chsrc 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。