-
Notifications
You must be signed in to change notification settings - Fork 13
Add misc safe rules #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add misc safe rules #264
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1b4d7c
Add misc safe rules
lucic71 184231c
Add conversion function for Dirent
lucic71 1d6add1
Drop the unnecessary_casts
lucic71 4e4ba6d
Add conversion from nix::Dir to CDir
lucic71 635bbac
Revert "Drop the unnecessary_casts"
lucic71 4f6bc2f
Set errno on getpwuid error
lucic71 679e2e3
Update tests
lucic71 f808c20
Add localization todo
lucic71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (c) 2022-present INESC-ID. | ||
| // Distributed under the MIT license that can be found in the LICENSE file. | ||
|
|
||
| use libcc2rs::*; | ||
|
|
||
| // Rust does not have support for localization. | ||
| // | ||
| // TODO: we need to track ourselves the locale settings and change the behavior of the relevant | ||
| // functions based on the set locale. | ||
| fn f1(a0: i32, a1: Ptr<u8>) -> Ptr<u8> { | ||
| Ptr::from_string_literal(b"C") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| // no-compile: refcount | ||
| #include <dirent.h> | ||
| #include <pwd.h> | ||
| #include <unistd.h> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| extern crate libcc2rs; | ||
| use libcc2rs::*; | ||
| use std::cell::RefCell; | ||
| use std::collections::BTreeMap; | ||
| use std::io::prelude::*; | ||
| use std::io::{Read, Seek, Write}; | ||
| use std::os::fd::AsFd; | ||
| use std::rc::{Rc, Weak}; | ||
| pub fn main() { | ||
| std::process::exit(main_0()); | ||
| } | ||
| fn main_0() -> i32 { | ||
| let pw: Value<Ptr<libcc2rs::Passwd>> = Rc::new(RefCell::new( | ||
| match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw( | ||
| nix::unistd::geteuid().as_raw(), | ||
| )) { | ||
| Ok(Some(__u)) => Ptr::alloc(Passwd::from_user(&__u)), | ||
| Ok(None) => Ptr::null(), | ||
| Err(__e) => { | ||
| libcc2rs::cpp2rust_errno().write(__e as i32); | ||
| Ptr::null() | ||
| } | ||
| }, | ||
| )); | ||
| if !!(*pw.borrow()).is_null() { | ||
| return 0; | ||
| } | ||
| let home: Value<Ptr<u8>> = Rc::new(RefCell::new( | ||
| (*(*(*pw.borrow()).upgrade().deref()).pw_dir.borrow()).clone(), | ||
| )); | ||
| let d: Value<Ptr<libcc2rs::Dirent>> = Rc::new(RefCell::new( | ||
| match nix::dir::Dir::open( | ||
| Ptr::from_string_literal(b"/tmp").to_rust_string().as_str(), | ||
| nix::fcntl::OFlag::O_RDONLY, | ||
| nix::sys::stat::Mode::empty(), | ||
| ) { | ||
| Ok(__dir) => Ptr::alloc(CDir::from_dir(__dir)), | ||
| Err(__e) => { | ||
| libcc2rs::cpp2rust_errno().write(__e as i32); | ||
| Ptr::null() | ||
| } | ||
| } | ||
| .with(|__d| { | ||
| let __i = __d.pos.get(); | ||
| if __i >= __d.entries.len() { | ||
| Ptr::null() | ||
| } else { | ||
| __d.pos.set(__i + 1); | ||
| let __e = &__d.entries[__i]; | ||
| Ptr::alloc(Dirent::from_entry(__e.0, &__e.1, __e.2)) | ||
| } | ||
| }), | ||
| )); | ||
| let dname: Value<Ptr<u8>> = Rc::new(RefCell::new( | ||
| ((*(*d.borrow()).upgrade().deref()).d_name.as_pointer() as Ptr<u8>), | ||
| )); | ||
| return 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not correct for sure :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust does not seem to have support for localization
The man page of setlocale says:
So the real options here are to return C (
The locale "C" or "POSIX" is a portable locale; it exists on all conforming systems.) or NULL. NULL looks more like a failure, so I chose "C" instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to track the locale ourselves and change the behavior of relevant string functions then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a TODO about that