Page MenuHomeFreeBSD

kern: devctl: add devctl_safe_quote_sb_len
Needs ReviewPublic

Authored by kevans on Mar 9 2022, 12:38 AM.
Tags
None
Referenced Files
F106831391: D34495.diff
Mon, Jan 6, 3:09 AM
Unknown Object (File)
Thu, Dec 19, 5:13 AM
Unknown Object (File)
Wed, Dec 18, 5:02 AM
Unknown Object (File)
Sat, Dec 14, 4:45 PM
Unknown Object (File)
Sat, Dec 14, 10:19 AM
Unknown Object (File)
Tue, Dec 10, 10:56 PM
Unknown Object (File)
Dec 4 2024, 1:25 AM
Unknown Object (File)
Dec 1 2024, 11:43 AM

Details

Reviewers
imp
adrian
cy
pauamma_gundo.com
Group Reviewers
manpages
Summary

This will be used momentarily to support quoting strings that aren't
guaranteed to be NUL terminated, but may have a length we can use.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 44749
Build 41637: arc lint + arc unit

Event Timeline

kevans created this revision.
sys/kern/subr_bus.c
898

I'd be happier with < len here.

904

How arbitrary? The function you copied this from assumes no newlines in the string either. Is that a possibility with your intended use case?

sys/kern/subr_bus.c
904

Nah, if an ssid contains non-printable characters (< ' ') we typically resort to hex output for the entire ssid -- and we do resort to hex output in the future caller.

OK. I'm sold on this one.

This revision is now accepted and ready to land.Mar 9 2022, 5:00 AM
imp requested changes to this revision.Mar 9 2022, 5:22 AM

On second thought, please update devctl_safe_quote_sb.9 for this alternative interface.

This revision now requires changes to proceed.Mar 9 2022, 5:22 AM
pauamma_gundo.com added inline comments.
share/man/man9/devctl_safe_quote_sb.9
52

Or maybe "a quoted string".

57–59

My C is very rusty, but the source code, to me, reads like len is applied to the source string, not the buffer, which would have to hold up to 2*len characters, for a string that contains only \ or " characters. Can you clarify which is intended?

This revision now requires changes to proceed.Mar 10 2022, 4:10 AM
share/man/man9/devctl_safe_quote_sb.9
52

"protocol requires a quoted string to have these special characters quoted."

is likely better.

57–59

sbuf automatically grows the size of the buffer, so you don't have to manage these things.

share/man/man9/devctl_safe_quote_sb.9
57–59

sbuf automatically grows the size of the buffer, so you don't have to manage these things.

That bit of the manual page says that len is a limit applied to the buffer. My (admittedly very rusty) C tells me the source code is applying that limit to the source string. You said the buffer doesn't need it, and that's consistent with how I read the source code, but the inconsistency with the manual page still needs to be addressed.

share/man/man9/devctl_safe_quote_sb.9
57–59

This was based in the verbiage of the comment above the function:

* @param src	Original buffer.
share/man/man9/devctl_safe_quote_sb.9
57–59

(arguably, it's not a string anymore if it's not guaranteed to be NUL terminated)

How about I just change it to
.Va src
instead?

share/man/man9/devctl_safe_quote_sb.9
57–59

That WFM.

kevans added inline comments.
share/man/man9/devctl_safe_quote_sb.9
52

I went with roughly this latest version, though I think "[...] escaped." makes more sense to me, since we're not actually further quoting anything but rather escaping existing quotes and escaping previous escapes.

kevans marked an inline comment as done.

Updates

Manual page LGTM now. I can't vouch for consistency with the source code beyond the one point I raised.