Comments (6)
I don't remember the details here.
While a NUL is required for SUN_LEN()
, all OSes I've tested except OpenBSD accepts and returns addresses that are just long enough to not leave space for a NUL within sun_len but otherwise fit. This is tested by max_path_addr()
in tests/addr.rs.
I don't know whether it's documented, I assume the worst that can happen if an OS doesn't support it is that you get an error when you try to use it. (As long as it works, any code that uses SUN_LEN()
on unknown addresses is in my opinion incorrect.)
The as_raw()
functions should document that path addresses might not be NUL-terminated though.
This function is used by all functions that return an address, and has some tests that test it directly. But I see that the error cases are not tested, and that it likely accepts paths one too long on OpenBSD.
I agree the code here is confusing, as I at first thought it was removing the last character from addresses!
It's only stripping NUL if it would be outside of sockaddr_un
, but otherwise ensures there is a NUL after it if there is space.
It does include the NUL in the length when there's space for it, is that wrong?
from_path()
also does that, so it doesn't seem to cause any problem and I'd be wary of changing it.
from uds.
I assume the worst that can happen if an OS doesn't support it is that you get an error when you try to use it
Could also hit a buffer overrun.
I'd be more comfortable with code here that followed documented semantics.
from uds.
Is it code calling as_raw()
or getting passed an address from it that might have buffer overruns, or are you also worried about the libc functions this library calls?
I want this library to be usable with all addresses that other programs might create.
So if it's only the former, I'd rather deprecate and remove the as_raw()
methods than reject usable addresses.
from uds.
Yes, I'm worried about this producing bad values that get passed down to libc.
from uds.
The FreeBSD man page you linked to also says
Unix-domain addresses are variable-length file system pathnames of at most 104 characters.
The include file <sys/un.h> defines this address:struct sockaddr_un { u_char sun_len; u_char sun_family; char sun_path[104]; };
and combined with your quote it sounds like it's only for using SUN_LEN()
that a NUL terminator is required, but that it's otherwise not needed.
The NetBSD man page says the same, and the DragonflyBSD man page doesn't mention SUN_LEN()
or NUL.
The Illumos man page however says it should be NUL-terminated, so I'll at least redux max length for it and probably make that the default for unknown OSes.
I haven't found a man page for macOS, but it accepts even longer paths.
from uds.
Yes please, it would be good if the defaults were safe and the deviations from the defaults were strongly documented, linking to these man pages.
from uds.
Related Issues (8)
- Tokio support HOT 1
- Read/write timeout HOT 2
- Compile error for android target HOT 2
- Tokio latest version possibility. HOT 2
- Undefined behavior: alloc() should be alloc_zeroed() HOT 2
- Undefined behavior: CMSG_DATA and CMSG_NXTHDR may return null HOT 2
- Unsoundness: Incorrect safety invariant checks in UnixSocketAddr::from_raw() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uds.