Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Release notes for `rustnetconf`, `rustnetconf-cli`, and `rustnetconf-yang`. See the [README](README.md) for current usage.

## What's New in v0.19.5

**Fix: the 0.19.4 bare-text repair now accepts a prefixed root.** cSRX answers `<command format="json">` with `<nc:rpc-reply xmlns:nc=…>` around the bare JSON, which 0.19.4 only matched as `<rpc-reply`, so it still failed with `RpcError::ParseError`. The repair now takes the root's own name (`rpc-reply` or `<prefix>:rpc-reply`), matches its close tag, and gives a synthesized `<rpc-error>` the same prefix. No API change.

## What's New in v0.19.4

**Fix: two Junos replies whose body is bare text now parse instead of failing with `RpcError::ParseError`.**
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ unsafe_code = "forbid"

[package]
name = "rustnetconf"
version = "0.19.4"
version = "0.19.5"
edition = "2021"
rust-version = "1.89"
authors = ["fastrevmd-lab"]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- mechub-version: v0.19.4 -->
<!-- mechub-version: v0.19.5 -->

<p align="center">
<picture>
Expand Down Expand Up @@ -26,9 +26,9 @@ Async NETCONF client library, YANG code generation, vendor profiles, connection

Built on [tokio](https://tokio.rs), [russh](https://crates.io/crates/russh), and [rustls](https://crates.io/crates/rustls) — pure Rust, no OpenSSL, no libssh2.

> **Latest release — [v0.19.4](https://github.com/mechubsec/rustnetconf/releases/tag/v0.19.4)** (2026-11-30): two Junos bare-text replies now parse: a Junos OS Evolved `protocol: … / error: …` failure becomes `RpcError::ServerError`, and a `<command format="json">` reply becomes `<output>` text. No API change.
> On crates.io: `rustnetconf` 0.19.4 · `rustnetconf-cli` 0.5.4 · `rustnetconf-yang` 0.6.0.
> See [CHANGELOG.md](CHANGELOG.md#whats-new-in-v0194) for release notes.
> **Latest release — [v0.19.5](https://github.com/mechubsec/rustnetconf/releases/tag/v0.19.5)** (2026-11-30): the 0.19.4 bare-text repair now also handles a prefixed root (`<nc:rpc-reply>`, as cSRX sends), so `<command format="json">` on cSRX parses. No API change.
> On crates.io: `rustnetconf` 0.19.5 · `rustnetconf-cli` 0.5.4 · `rustnetconf-yang` 0.6.0.
> See [CHANGELOG.md](CHANGELOG.md#whats-new-in-v0195) for release notes.

## Install

Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/rpc/reply/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,4 +1370,31 @@ mod tests {
assert!(data.starts_with("<output>{"), "{data}");
assert!(data.contains("x&lt;y&amp;z"), "{data}");
}

/// cSRX prefixes the root (`<nc:rpc-reply xmlns:nc=...>`).
#[test]
fn prefixed_root_bare_replies_are_repaired() {
let open =
"<nc:rpc-reply xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">";
let xml = format!("{open}\n{{\n \"a\" : \"x<y\"\n}}\n</nc:rpc-reply>\n");
let RpcReply::Data(data) = parse_rpc_reply(&xml, "1").unwrap() else {
panic!("expected Data");
};
assert!(data.contains("x&lt;y"), "{data}");

let xml = format!(
"{open}\nprotocol: operation-failed\nerror: the l2cpd-service subsystem is not running\n</nc:rpc-reply>"
);
let err = parse_rpc_reply(&xml, "1").unwrap_err();
let RpcError::ServerError(server_error) = err else {
panic!("expected ServerError, got {err:?}");
};
assert_eq!(server_error.tag, ErrorTag::OperationFailed);

let mismatched = format!("{open}\n{{}}\n</rpc-reply>");
assert!(matches!(
parse_rpc_reply(&mismatched, "1"),
Err(RpcError::ParseError(_))
));
}
}
22 changes: 17 additions & 5 deletions src/rpc/reply/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,25 @@ fn event_allowed_outside_root(event: &Event<'_>, root_state: DocumentRootState)
/// `<type>: <tag>`, and a second line `error: <message>`. Anything else
/// returns `None` so the strict parse error stands.
pub(super) fn repair_bare_text_error(xml: &str) -> Option<String> {
let open_end = xml.find("<rpc-reply")?;
let open_end = xml.len() - xml.trim_start().len();
let name = xml[open_end..]
.strip_prefix('<')?
.split(|c: char| c.is_whitespace() || c == '>' || c == '/')
.next()?;
// cSRX prefixes the root (`<nc:rpc-reply>`); the synthesized error must
// carry the same prefix to stay in the NETCONF namespace.
let prefix = name.strip_suffix("rpc-reply")?;
if !(prefix.is_empty() || prefix.ends_with(':')) {
return None;
}
let tag_end = open_end + xml[open_end..].find('>')?;
if xml[open_end..tag_end].ends_with('/') {
return None;
}
let close = xml.rfind("</rpc-reply>")?;
let close_tag = format!("</{name}>");
let close = xml.rfind(&close_tag)?;
let (head, body, tail) = (&xml[..=tag_end], &xml[tag_end + 1..close], &xml[close..]);
if !head[..open_end].trim().is_empty() || !tail[12..].trim().is_empty() {
if !tail[close_tag.len()..].trim().is_empty() {
return None;
}
// `<command format="json">` replies carry the JSON document as bare text.
Expand All @@ -367,8 +378,9 @@ pub(super) fn repair_bare_text_error(xml: &str) -> Option<String> {
}
let message = quick_xml::escape::escape(message);
Some(format!(
"{head}<rpc-error><error-type>{error_type}</error-type><error-tag>{tag}</error-tag>\
<error-severity>error</error-severity><error-message>{message}</error-message></rpc-error>{tail}"
"{head}<{prefix}rpc-error><{prefix}error-type>{error_type}</{prefix}error-type>\
<{prefix}error-tag>{tag}</{prefix}error-tag><{prefix}error-severity>error</{prefix}error-severity>\
<{prefix}error-message>{message}</{prefix}error-message></{prefix}rpc-error>{tail}"
))
}

Expand Down
Loading