Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
278f840b
Commit
278f840b
authored
Sep 10, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check input
parent
0108702b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
1 deletion
+38
-1
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+31
-1
src/ast/semantic_analyser.h
src/ast/semantic_analyser.h
+1
-0
src/bpftrace.cpp
src/bpftrace.cpp
+1
-0
tests/codegen.cpp
tests/codegen.cpp
+5
-0
No files found.
src/ast/semantic_analyser.cpp
View file @
278f840b
...
...
@@ -5,6 +5,7 @@
#include "printf.h"
#include "arch/arch.h"
#include <sys/stat.h>
#include <regex>
#include "libbpf.h"
...
...
@@ -209,13 +210,24 @@ void SemanticAnalyser::visit(Call &call)
call
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
call
.
func
==
"kaddr"
||
call
.
func
==
"uaddr"
)
{
else
if
(
call
.
func
==
"kaddr"
)
{
if
(
check_nargs
(
call
,
1
))
{
if
(
check_arg
(
call
,
Type
::
string
,
0
,
true
))
{
;
}
}
call
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
call
.
func
==
"uaddr"
)
{
if
(
check_nargs
(
call
,
1
))
{
if
(
check_arg
(
call
,
Type
::
string
,
0
,
true
))
{
if
(
check_alpha_numeric
(
call
,
0
))
{
;
}
}
}
call
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
call
.
func
==
"printf"
)
{
check_assignment
(
call
,
false
,
false
);
...
...
@@ -909,5 +921,23 @@ bool SemanticAnalyser::check_arg(const Call &call, Type type, int arg_num, bool
return
true
;
}
bool
SemanticAnalyser
::
check_alpha_numeric
(
const
Call
&
call
,
int
arg_num
)
{
if
(
!
call
.
vargs
)
return
false
;
auto
&
arg
=
static_cast
<
String
&>
(
*
call
.
vargs
->
at
(
0
)).
str
;
bool
is_alpha
=
std
::
regex_match
(
arg
,
std
::
regex
(
"^[a-zA-Z0-9_-]+$"
));
if
(
!
is_alpha
)
{
err_
<<
call
.
func
<<
"() expects an alpha numeric string as input"
;
err_
<<
" (
\"
"
<<
arg
<<
"
\"
provided)"
<<
std
::
endl
;
return
false
;
}
return
true
;
}
}
// namespace ast
}
// namespace bpftrace
src/ast/semantic_analyser.h
View file @
278f840b
...
...
@@ -55,6 +55,7 @@ private:
bool
check_nargs
(
const
Call
&
call
,
int
expected_nargs
);
bool
check_varargs
(
const
Call
&
call
,
int
min_nargs
,
int
max_nargs
);
bool
check_arg
(
const
Call
&
call
,
Type
type
,
int
arg_num
,
bool
want_literal
=
false
);
bool
check_alpha_numeric
(
const
Call
&
call
,
int
arg_num
);
Probe
*
probe_
;
std
::
map
<
std
::
string
,
SizedType
>
variable_val_
;
...
...
src/bpftrace.cpp
View file @
278f840b
...
...
@@ -1158,6 +1158,7 @@ uint64_t BPFtrace::resolve_uname(const char *name)
{
uint64_t
addr
=
0
;
// TODO: switch from objdump to library call
std
::
string
call_str
=
"objdump -tT /bin/bash | grep "
;
call_str
+=
name
;
const
char
*
call
=
call_str
.
c_str
();
...
...
tests/codegen.cpp
View file @
278f840b
...
...
@@ -1029,6 +1029,11 @@ TEST(codegen, call_kaddr)
// TODO: test kaddr()
}
TEST
(
codegen
,
call_uaddr
)
{
// TODO: test uaddr()
}
TEST
(
codegen
,
call_hist
)
{
test
(
"kprobe:f { @x = hist(pid) }"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment