Skip to content

Conversation

@brainstorm
Copy link
Contributor

@brainstorm brainstorm commented Sep 9, 2025

Adds the necessary structs/types/event for env var sending/handling (and avoids runtime message: WARN - Unknown channel req type 'env')... that's according to RFC 4254, but we'll deem more env vars as 'safe to pass' than just LANG, TERM, and DISPLAY. I.e (potentially with SSH_STAMP_ prefix):

UART_TX_PIN and UART_RX_PIN
WIFI_SSID, WIFI_PW
GENERATE_HOST_KEY
PUBLIC_KEY, etc...

This PR is essential to implement support on brainstorm/ssh-stamp#44.

/cc @mmalenic

@brainstorm
Copy link
Contributor Author

brainstorm commented Nov 13, 2025

Yay, working now:

[src/serve.rs:98] "Got ENV request" = "Got ENV request"
[src/serve.rs:99] a.name()? = "LANG"
[src/serve.rs:100] a.value()? = "C.UTF-8"
[src/serve.rs:41] &ev = ServEvent(PollAgain)
[src/serve.rs:41] &ev = ServEvent(Environment)
[src/serve.rs:98] "Got ENV request" = "Got ENV request"
[src/serve.rs:99] a.name()? = "UART_RX_PIN"
[src/serve.rs:100] a.value()? = "10"

Will cleanup (remove ipv6 cfg that doesn't belong here) and mark it ready for review later on. Done!

@mkj Please review? :)

… Unknown channel req type 'env')... that's according to RFC 4254, but we'll deem more env vars as 'safe to pass' than just LANG, TERM, and DISPLAY.

[src/serve.rs:98] "Got ENV request" = "Got ENV request"
[src/serve.rs:99] a.name()? = "LANG"
[src/serve.rs:100] a.value()? = "C.UTF-8"

Co-authored-by: Marko Malenic <[email protected]>
Co-authored-by: Julio Beltran Ortega <[email protected]>
@brainstorm brainstorm marked this pull request as ready for review November 13, 2025 06:25
Copy link
Owner

@mkj mkj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good. One small comment on naming.

The docs could maybe have a note that the strings are not sanitised, so if they're passed to a shell/C FFI etc the application needs to be careful (strip \0 etc). That probably applies to username/password as well - I can have a look at that, no need to hold up this PR.

@brainstorm
Copy link
Contributor Author

brainstorm commented Nov 17, 2025

The docs could maybe have a note that the strings are not sanitised, so if they're passed to a shell/C FFI etc the application needs to be careful (strip \0 etc). That probably applies to username/password as well - I can have a look at that, no need to hold up this PR.

Thanks Matt! I did think a bit about input sanitisation/validation but honestly I didn't know how much of it you wanted to include at the lib level so I left it a bit open for now... perhaps the length of both name and value should ideally be clipped to reasonable defaults while you are at it?... among other input validation standard recommendations.

@mkj mkj merged commit 490b830 into mkj:main Nov 17, 2025
3 checks passed
@mkj
Copy link
Owner

mkj commented Nov 17, 2025

perhaps the length of both name and value should ideally be clipped to reasonable defaults while you are at it?... among other input validation standard recommendations

I don't think the core library needs to do it - the name/value are slices of the input packet, so don't use any space beyond the fixed input buffer. On embedded platforms to keep a string copy I assume they're usually using heapless::String or similar with an upper limit, and when creating the string they'll have to be error checking the constructor. On non-embedded platforms I guess there might be a risk of multiple large heap allocations, but that's a bit hard to prevent from Sunset's side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants