Dry-run mode writes to /etc/apt/sources.list on the legacy Debian/Ubuntu source-list path
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Leggi src/recipe/os/APT/common.h intorno a ensure_debian_or_ubuntu_old_sourcelist() e confronta la sua scrittura con il percorso che supporta il dry-run in src/framework/OS.c. Controlla i punti di chiamata Debian e Ubuntu elencati nell’issue, quindi esegui i test pertinenti del progetto oppure riproduci il caso con chsrc set -dry debian quando il vecchio file dell’elenco delle sorgenti è assente. Il lavoro è completato quando il dry-run non crea /etc/apt/sources.list e la funzione mantiene il comportamento di ritorno indicato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C
- Stelle
- 6.9k
- Fork
- 285
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RubyMetric/chsrc
-
Bug:Windows 下 Bun 换源功能异常Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
RubyMetric/chsrc#399 ·
-
是否考虑新增自定义源增加别名Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
RubyMetric/chsrc#398 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 22/100
RubyMetric/chsrc#397 ·
-
[arch] 多次 chsrc set arch 后 mirrorlist 累积旧 Server 行,upstream 官方源地址无效Forse di nuovo libera @yayoinoyume l’ha presa 35 giorni fa e non c’è nessuna pull request aperta. ApertaLinux os_dish 源
RubyMetric/chsrc#393 · 2 commenti · 2 reazioni · 1 assegnatario ·
-
`ls` 命令呈现 "可用源" 的界面有改进空间Forse di nuovo libera @ccmywish l’ha presa 36 giorni fa e non c’è nessuna pull request aperta. Aperta改善加强
RubyMetric/chsrc#389 · 6 commenti · 1 assegnatario ·
Tutte le issue di RubyMetric/chsrc
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
KalicoCrew/kalico#1012 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
joncampbell123/dosbox-x#6664 ·
I maintainer di solito rispondono entro 1 giorno
-
fails to compile with Qt6Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
osam-cologne/archlinux-proaudio#909 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
tpm2-software/tpm2-abrmd#879 ·
I maintainer di solito rispondono entro 1 giorno