Skip to content

Commit ebb42be

Browse files
socket::unix: fix bind function
* ensure not abstract-namespace * fix socket structures Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 2f19b03 commit ebb42be

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/aero_kernel/src/fs/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub enum FileSystemError {
131131
IsPipe,
132132
Interrupted,
133133
TooSmall,
134+
InvalidPath,
134135
}
135136

136137
impl From<FileSystemError> for AeroSyscallError {
@@ -144,6 +145,7 @@ impl From<FileSystemError> for AeroSyscallError {
144145
FileSystemError::IsPipe => AeroSyscallError::ESPIPE,
145146
FileSystemError::Interrupted => AeroSyscallError::EINTR,
146147
FileSystemError::TooSmall => AeroSyscallError::E2BIG,
148+
FileSystemError::InvalidPath => AeroSyscallError::EINVAL,
147149
}
148150
}
149151
}

src/aero_kernel/src/socket/unix.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ impl INodeInterface for UnixSocket {
5151

5252
fn bind(&self, address: SocketAddr, _length: usize) -> Result<()> {
5353
if let SocketAddr::Unix(address) = address {
54+
// The abstract namespace socket allows the creation of a socket
55+
// connection which does not require a path to be created.
56+
let abstrat_namespaced = address.path[0] == 0;
57+
assert!(!abstrat_namespaced);
58+
5459
let path_len = address
5560
.path
5661
.iter()
57-
.position(|&b| b == 0)
62+
.position(|&c| c == 0)
5863
.unwrap_or(address.path.len());
5964

60-
let path_str = unsafe { core::str::from_utf8_unchecked(&address.path[0..path_len]) };
65+
let path_str = core::str::from_utf8(&address.path[..path_len])
66+
.ok()
67+
.ok_or(FileSystemError::InvalidPath)?;
68+
6169
let path = Path::new(path_str);
6270

71+
// Ensure that the path is not already in use.
6372
if fs::lookup_path(path).is_ok() {
6473
return Err(FileSystemError::EntryExists);
6574
}

src/aero_kernel/src/syscall/fs.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ pub fn pipe(fds: &mut [usize; 2], flags: usize) -> Result<usize, AeroSyscallErro
276276

277277
#[aero_proc::syscall]
278278
pub fn unlink(fd: usize, path: &Path, flags: usize) -> Result<usize, AeroSyscallError> {
279-
log::debug!("{path:?}");
280-
281279
// TODO: Make use of the open flags.
282280
let _flags = OpenFlags::from_bits(flags).ok_or(AeroSyscallError::EINVAL)?;
283281
let name = path.container();

src/aero_syscall/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,14 @@ pub fn sys_sethostname(name: &str) -> Result<usize, AeroSyscallError> {
661661
#[derive(Debug, Clone)]
662662
#[repr(C)]
663663
pub struct SocketAddrUnix {
664-
pub family: i16,
664+
pub family: u32,
665665
pub path: [u8; 108],
666666
}
667667

668668
#[derive(Debug, Clone)]
669669
#[repr(C)]
670670
pub struct SocketAddrInet {
671-
pub family: i16,
671+
pub family: u32,
672672
pub port: [u8; 2],
673673
pub address: [u8; 4],
674674
pub padding: [u8; 8],

0 commit comments

Comments
 (0)