Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tornax O7
relibc
Commits
b0dde81c
Verified
Commit
b0dde81c
authored
4 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Handle missing paths in load_library search without using access
parent
d9bacaec
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ld_so/linker.rs
+37
-17
37 additions, 17 deletions
src/ld_so/linker.rs
with
37 additions
and
17 deletions
src/ld_so/linker.rs
+
37
−
17
View file @
b0dde81c
...
@@ -21,7 +21,7 @@ use crate::{
...
@@ -21,7 +21,7 @@ use crate::{
c_str
::
CString
,
c_str
::
CString
,
fs
::
File
,
fs
::
File
,
header
::{
fcntl
,
sys_mman
,
unistd
},
header
::{
fcntl
,
sys_mman
,
unistd
},
io
::
Read
,
io
::
{
self
,
Read
}
,
platform
::
types
::
c_void
,
platform
::
types
::
c_void
,
};
};
...
@@ -94,41 +94,54 @@ impl Linker {
...
@@ -94,41 +94,54 @@ impl Linker {
}
}
pub
fn
load
(
&
mut
self
,
name
:
&
str
,
path
:
&
str
)
->
Result
<
()
>
{
pub
fn
load
(
&
mut
self
,
name
:
&
str
,
path
:
&
str
)
->
Result
<
()
>
{
self
.dep_tree
=
self
.load_recursive
(
name
,
path
)
?
;
self
.dep_tree
=
self
.load_recursive
(
name
,
path
)
?
.ok_or
(
Error
::
Malformed
(
format!
(
"failed to find '{}'"
,
path
)))
?
;
if
self
.verbose
{
if
self
.verbose
{
println!
(
"Dep tree: {:#?}"
,
self
.dep_tree
);
println!
(
"Dep tree: {:#?}"
,
self
.dep_tree
);
}
}
return
Ok
(());
return
Ok
(());
}
}
fn
load_recursive
(
&
mut
self
,
name
:
&
str
,
path
:
&
str
)
->
Result
<
DepTree
>
{
fn
load_recursive
(
&
mut
self
,
name
:
&
str
,
path
:
&
str
)
->
Result
<
Option
<
DepTree
>
>
{
if
self
.verbose
{
if
self
.verbose
{
println!
(
"load {}: {}"
,
name
,
path
);
println!
(
"load {}: {}"
,
name
,
path
);
}
}
if
self
.cir_dep
.contains
(
name
)
{
return
Err
(
Error
::
Malformed
(
format!
(
"Circular dependency: {} is a dependency of itself"
,
name
)));
}
let
mut
deps
=
DepTree
::
new
(
name
.to_string
());
let
mut
data
=
Vec
::
new
();
self
.cir_dep
.insert
(
name
.to_string
());
let
path_c
=
CString
::
new
(
path
)
let
path_c
=
CString
::
new
(
path
)
.map_err
(|
err
|
Error
::
Malformed
(
format!
(
"invalid path '{}': {}"
,
path
,
err
)))
?
;
.map_err
(|
err
|
Error
::
Malformed
(
format!
(
"invalid path '{}': {}"
,
path
,
err
)))
?
;
let
mut
data
=
Vec
::
new
();
{
{
let
flags
=
fcntl
::
O_RDONLY
|
fcntl
::
O_CLOEXEC
;
let
flags
=
fcntl
::
O_RDONLY
|
fcntl
::
O_CLOEXEC
;
let
mut
file
=
File
::
open
(
&
path_c
,
flags
)
let
mut
file
=
match
File
::
open
(
&
path_c
,
flags
)
{
.map_err
(|
err
|
Error
::
Malformed
(
format!
(
"failed to open '{}': {}"
,
path
,
err
)))
?
;
Ok
(
ok
)
=>
ok
,
Err
(
err
)
=>
match
err
.kind
()
{
io
::
ErrorKind
::
NotFound
=>
return
Ok
(
None
),
_
=>
return
Err
(
Error
::
Malformed
(
format!
(
"failed to open '{}': {}"
,
path
,
err
)))
}
};
file
.read_to_end
(
&
mut
data
)
file
.read_to_end
(
&
mut
data
)
.map_err
(|
err
|
Error
::
Malformed
(
format!
(
"failed to read '{}': {}"
,
path
,
err
)))
?
;
.map_err
(|
err
|
Error
::
Malformed
(
format!
(
"failed to read '{}': {}"
,
path
,
err
)))
?
;
}
}
if
self
.cir_dep
.contains
(
name
)
{
return
Err
(
Error
::
Malformed
(
format!
(
"Circular dependency: {} is a dependency of itself"
,
name
)));
}
self
.cir_dep
.insert
(
name
.to_string
());
let
mut
deps
=
DepTree
::
new
(
name
.to_string
());
deps
.deps
=
self
.load_data
(
name
,
data
.into_boxed_slice
())
?
;
deps
.deps
=
self
.load_data
(
name
,
data
.into_boxed_slice
())
?
;
self
.cir_dep
.remove
(
name
);
self
.cir_dep
.remove
(
name
);
Ok
(
deps
)
Ok
(
Some
(
deps
))
}
}
pub
fn
load_data
(
&
mut
self
,
name
:
&
str
,
data
:
Box
<
[
u8
]
>
)
->
Result
<
Vec
<
DepTree
>>
{
pub
fn
load_data
(
&
mut
self
,
name
:
&
str
,
data
:
Box
<
[
u8
]
>
)
->
Result
<
Vec
<
DepTree
>>
{
...
@@ -151,7 +164,12 @@ impl Linker {
...
@@ -151,7 +164,12 @@ impl Linker {
// It should be previously resolved so we don't need to worry about it
// It should be previously resolved so we don't need to worry about it
Ok
(
None
)
Ok
(
None
)
}
else
if
name
.contains
(
'/'
)
{
}
else
if
name
.contains
(
'/'
)
{
Ok
(
Some
(
self
.load_recursive
(
name
,
name
)
?
))
Ok
(
Some
(
self
.load_recursive
(
name
,
name
)
?
.ok_or
(
Error
::
Malformed
(
format!
(
"failed to find '{}'"
,
name
)))
?
))
}
else
{
}
else
{
let
library_path
=
self
.library_path
.clone
();
let
library_path
=
self
.library_path
.clone
();
for
part
in
library_path
.split
(
PATH_SEP
)
{
for
part
in
library_path
.split
(
PATH_SEP
)
{
...
@@ -163,7 +181,9 @@ impl Linker {
...
@@ -163,7 +181,9 @@ impl Linker {
if
self
.verbose
{
if
self
.verbose
{
println!
(
"check {}"
,
path
);
println!
(
"check {}"
,
path
);
}
}
return
Ok
(
Some
(
self
.load_recursive
(
name
,
&
path
)
?
));
if
let
Some
(
deps
)
=
self
.load_recursive
(
name
,
&
path
)
?
{
return
Ok
(
Some
(
deps
));
}
}
}
Err
(
Error
::
Malformed
(
format!
(
"failed to locate '{}'"
,
name
)))
Err
(
Error
::
Malformed
(
format!
(
"failed to locate '{}'"
,
name
)))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment