Dry-run mode writes to /etc/apt/sources.list on the legacy Debian/Ubuntu source-list path
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 82/100
Piste de recherche
Lisez src/recipe/os/APT/common.h autour de ensure_debian_or_ubuntu_old_sourcelist() et comparez son écriture avec le chemin compatible avec le dry-run dans src/framework/OS.c. Vérifiez les sites d’appel Debian et Ubuntu répertoriés dans l’issue, puis exécutez les tests pertinents du projet ou reproduisez le cas avec chsrc set -dry debian lorsque l’ancien fichier de liste des sources est absent. Le travail est terminé lorsque le dry-run ne crée pas /etc/apt/sources.list et que la fonction conserve le comportement de retour indiqué.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- C
- Étoiles
- 6.9k
- Forks
- 285
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de RubyMetric/chsrc
-
[arch] 多次 chsrc set arch 后 mirrorlist 累积旧 Server 行,upstream 官方源地址无效Peut-être à nouveau libre @yayoinoyume l’a pris il y a 30 jours, et aucune pull request n’est ouverte. OuverteLinux os_dish 源
RubyMetric/chsrc#393 · 2 commentaires · 2 réactions · 1 personne assignée ·
-
`ls` 命令呈现 "可用源" 的界面有改进空间Peut-être à nouveau libre @ccmywish l’a pris il y a 32 jours, et aucune pull request n’est ouverte. Ouverte改善加强
RubyMetric/chsrc#389 · 6 commentaires · 1 personne assignée ·
-
对 `Omarchy`(基于 Arch Linux 的发行版)的支持Peut-être à nouveau libre @yayoinoyume l’a pris il y a 32 jours, et aucune pull request n’est ouverte. OuverteLinux os_dish
RubyMetric/chsrc#387 · 8 commentaires · 1 réaction · 1 personne assignée ·
-
`curl` 测速 段错误 (核心已转储)Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 48/100
RubyMetric/chsrc#386 · 4 commentaires ·
-
对 `sources dish` 贡献者的展示Peut-être à nouveau libre @ccmywish l’a pris il y a 46 jours, et aucune pull request n’est ouverte. Ouverte改善加强
RubyMetric/chsrc#384 · 5 commentaires · 1 personne assignée ·
Toutes les issues de RubyMetric/chsrc
Issues similaires
-
Linux notifications: the default action's ' ' label shows as a blank button in xfce4-notifydOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
kovidgoyal/kitty#10625 ·
Les mainteneurs répondent en général sous 1 jour
-
Feature Status: Needs Triage
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
Les mainteneurs répondent en général sous 1 jour
-
docs
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
本機相簿無法上傳webm檔案Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
xiaojieonly/Ehviewer_CN_SXJ#2893 ·