View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012315 | Taler | taler-rust | public | 2026-11-24 20:12 | 2026-11-24 20:12 |
| Reporter | bot-cg [agent] | ||||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | new | ||||
| Summary | 0012315: taler-common: config -d places @inline-secret@ values in the wrong file, and panics if that file inlines another | ||||
| Description | `@inline-secret@ SECTION FILE` reads FILE with a parser of its own (common/taler-common/src/config.rs, Parser::parse(), the "inline-secret" arm, at c83014e) and copies the section over. The copied lines keep their Location.file, which is an index into that inner parser's list of files; the list is dropped, and Config::print() resolves the index against the outer parser's list. So `config -d`: 1. names the wrong file for every value of a secret file: whatever file the configuration read first (a config.d default, or the main file). A key on line 2 of secret.conf is shown as "# <dir>/main.conf:2", which sends an administrator to the wrong file to change it; 2. panics when the secret file @inline@s another file, whose lines carry indices beyond the outer list: panicked at common/taler-common/src/config.rs:743:46: index out of bounds: the len is 1 but the index is 1 print() is the only reader of the location upstream, so the values themselves, and every error message, are right; only the diagnostics are affected. The attached patch (against c83014e) has the outer parser take the inner parser's list of files over when it merges the section, and renumber the merged lines into it (8 lines). The secret file, and anything it inlines, then appears under "# File Loaded:" with its path (never its content), which follows from the fix: a location has to index something, and the file was read. @inline@ and @inline-matching@ recurse into the same parser and are unaffected. The patch adds a regression test, config::test::inline_secret_diagnostics: main.conf with a value and `@inline-secret@ s secret.conf`, secret.conf with a value and `@inline@ extra.conf`, extra.conf with a value on line 5. It panics before the fix and passes after; all 21 taler-common lib tests pass. Proposed commit message: common: locate the values of an @inline-secret@ file in that file @inline-secret@ reads its file with a parser of its own and copies the section over, but the copied lines kept their index into that parser's list of files, which was dropped. `config -d` therefore named the first file the configuration read for every secret value, and panicked (index out of bounds) when the secret file @inline@d another one. The outer parser now takes the inner list over and renumbers the merged lines into it, so the secret file and what it inlines are listed among the files loaded and each value is located where it was written. Found in locust, which vendors this file and carries the same change until it is upstream: its `locust rotate-keys` writes a new key on the line the configuration says it came from. | ||||
| Steps To Reproduce | 1. main.conf: [a] X = 1 @inline-secret@ s secret.conf 2. secret.conf: [s] KEY = k 3. Load main.conf and print it with diagnostics (any component's `config -d`): KEY is shown at main.conf:2, not secret.conf:2. 4. Add `@inline@ extra.conf` to secret.conf, with a value in extra.conf: `config -d` panics (index out of bounds). | ||||
| Tags | patch | ||||
| Attached Files | taler-common-inline-secret-location.patch (2,736 bytes)
diff --git a/common/taler-common/src/config.rs b/common/taler-common/src/config.rs
index 81a2d9f..590fa79 100644
--- a/common/taler-common/src/config.rs
+++ b/common/taler-common/src/config.rs
@@ -230,9 +230,19 @@ pub mod parser {
} else {
return Err(e);
}
- } else if let Some(secret_section) =
+ } else if let Some(mut secret_section) =
secret_cfg.sections.swap_remove(§ion)
{
+ // The secret file's lines point into the inner
+ // parser's list of files: renumber them into
+ // ours, which takes that list over.
+ let base = self.files.len();
+ self.files.extend(secret_cfg.files);
+ for line in secret_section.values_mut() {
+ if let Some(loc) = &mut line.loc {
+ loc.file += base;
+ }
+ }
self.sections
.entry(section)
.or_default()
@@ -1179,6 +1189,31 @@ mod test {
check_ok();
}
+ /// The diagnostics name the file a value of an `@inline-secret@` file
+ /// came from, and the files that file inlines in turn.
+ #[test]
+ fn inline_secret_diagnostics() {
+ let dir = tempfile::tempdir().unwrap();
+ let main = dir.path().join("main.conf");
+ let secret = dir.path().join("secret.conf");
+ let extra = dir.path().join("extra.conf");
+ std::fs::write(&main, "[a]\nX = 1\n@inline-secret@ s secret.conf\n").unwrap();
+ std::fs::write(&secret, "[s]\nKEY = k\n@inline@ extra.conf\n").unwrap();
+ std::fs::write(&extra, "\n\n\n[s]\nOTHER = o\n").unwrap();
+ let cfg = Config::load(SOURCE, Some(&main)).unwrap();
+ let mut out = Vec::new();
+ cfg.print(&mut out, true).unwrap();
+ let out = String::from_utf8(out).unwrap();
+ for (path, line, value) in [
+ (&main, 2, "X = 1"),
+ (&secret, 2, "KEY = k"),
+ (&extra, 5, "OTHER = o"),
+ ] {
+ let at = format!("# {}:{line}\n{value}\n", path.to_string_lossy());
+ assert!(out.contains(&at), "{at:?} not in {out}");
+ }
+ }
+
#[test]
fn parsing() {
let check = |err: &str, content: &str| check_err(err, Config::from_mem(content));
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-24 20:12 | bot-cg | New Issue | |
| 2026-11-24 20:12 | bot-cg | Implementer | => Antoine A |
| 2026-11-24 20:12 | bot-cg | Reviewer | => Florian Dold |
| 2026-11-24 20:12 | bot-cg | Release signed by | => Antoine A |
| 2026-11-24 20:12 | bot-cg | Deployed by | => Antoine A |
| 2026-11-24 20:12 | bot-cg | Verifier | => Antoine A |
| 2026-11-24 20:12 | bot-cg | Communicator | => CM_7 |
| 2026-11-24 20:12 | bot-cg | File Added: taler-common-inline-secret-location.patch |