Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipr Toolchain
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Open Source Software
Zipr Toolchain
Commits
0c9babe8
Commit
0c9babe8
authored
13 years ago
by
an7s
Browse files
Options
Downloads
Patches
Plain Diff
test program for integer bugs
parent
f9036d29
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitattributes
+1
-0
1 addition, 0 deletions
.gitattributes
examples/Makefile
+4
-3
4 additions, 3 deletions
examples/Makefile
examples/integerbug.c
+119
-0
119 additions, 0 deletions
examples/integerbug.c
with
124 additions
and
3 deletions
.gitattributes
+
1
−
0
View file @
0c9babe8
...
...
@@ -144,6 +144,7 @@ beaengine/obj/Linux.gnu.Debug/beaengineSources/CMakeFiles/progress.marks -text
examples/Makefile -text
examples/dumbledore.c -text
examples/dumbledore_cmd.c -text
examples/integerbug.c -text
examples/overflow1.c -text
examples/test1.c -text
libIRDB/Makefile -text
...
...
This diff is collapsed.
Click to expand it.
examples/Makefile
+
4
−
3
View file @
0c9babe8
...
...
@@ -6,8 +6,9 @@ LD=DO_NOT_USE
.SUFFIXES
:
.o .c .cpp .exe
#exes=dumbledore_cmd.exe test1.exe
exes
=
overflow1.exe
#overflow2.exe
#
exes=overflow1.exe #overflow2.exe
#exes=dumbledore_cmd.exe
exes
=
integerbug.exe
all
:
env_check ${exes}
...
...
@@ -15,8 +16,8 @@ all: env_check ${exes}
.PHONY
:
env_check
.o.exe
:
${
PEASOUP_HOME
}
/tools/ps_link.sh
$<
-o
$@
#
gcc $< -o $@
#
${PEASOUP_HOME}/tools/ps_link.sh $< -o $@
gcc
$<
-o
$@
${PEASOUP_HOME}/tools/ps_analyze.sh
$@
$@
.c.o
:
...
...
This diff is collapsed.
Click to expand it.
examples/integerbug.c
0 → 100644
+
119
−
0
View file @
0c9babe8
int
int_fussy_overflow
(
int
x
,
int
y
)
{
printf
(
"int_fussy_overflow: %d %d
\n
"
,
x
,
y
);
int
result
=
x
+
10000
-
y
;
return
result
;
}
unsigned
uint_fussy_overflow
(
unsigned
x
,
unsigned
y
)
{
printf
(
"uint_fussy_overflow: %u %u
\n
"
,
x
,
y
);
unsigned
result
=
x
+
10000
-
y
;
return
result
;
}
int
signed_overflow
(
int
x
,
int
y
)
{
printf
(
"signed_overflow: %d %d
\n
"
,
x
,
y
);
int
sum
=
x
+
y
;
return
sum
;
}
unsigned
unsigned_overflow
(
unsigned
x
,
unsigned
y
)
{
printf
(
"unsigned_overflow: %u %u
\n
"
,
x
,
y
);
unsigned
sum
=
x
+
y
;
return
sum
;
}
char
*
integer_overflow_into_malloc_1
(
unsigned
numElements
)
{
printf
(
"integer_overflow_into_malloc_1: %u
\n
"
,
numElements
);
unsigned
int
size
=
numElements
*
4
;
// compiler may use shifting here
char
*
buf
=
malloc
(
size
);
return
buf
;
}
char
*
integer_overflow_into_malloc_2
(
unsigned
numElements
,
unsigned
sizePerElement
)
{
printf
(
"integer_overflow_into_malloc_2: %u %u
\n
"
,
numElements
,
sizePerElement
);
unsigned
int
size
=
numElements
*
sizePerElement
;
char
*
buf
=
malloc
(
size
);
return
buf
;
}
char
*
integer_underflow
(
unsigned
len
,
char
*
src
)
{
printf
(
"integer_underflow: %d
\n
"
,
len
);
unsigned
int
size
;
size
=
len
-
2
;
// len = 0, size = -2
char
*
comm
=
(
char
*
)
malloc
(
size
+
1
);
// -1 (MAX_UNSIGNED_INT) passed to malloc
memcpy
(
comm
,
src
,
size
);
return
comm
;
}
char
*
signed_error
(
int
size
)
{
printf
(
"signed_error: %d
\n
"
,
size
);
return
malloc
(
size
);
}
int
signed_error_bypass_check
(
unsigned
value
)
{
printf
(
"signed_error_bypass_check: %u
\n
"
,
value
);
int
x
=
value
;
if
(
x
>
1024
)
{
printf
(
"too big
\n
"
);
return
1
;
}
else
{
printf
(
"passed upper bound check
\n
"
);
return
0
;
}
}
char
*
trunc_error
(
unsigned
size
,
int
numElements
)
{
printf
(
"trunc_error: %u %d
\n
"
,
size
,
numElements
);
short
len
=
size
;
return
malloc
(
len
*
numElements
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
selector
=
0
;
int
myint
;
int
result
;
char
*
bufptr
;
char
buf
[
16
]
=
"hello"
;
if
(
argc
==
2
)
selector
=
atoi
(
argv
[
1
]);
switch
(
selector
)
{
case
0
:
bufptr
=
integer_overflow_into_malloc_2
(
4
,
4
);
break
;
case
1
:
bufptr
=
integer_overflow_into_malloc_2
(
2000000000
,
4
);
break
;
case
2
:
bufptr
=
integer_overflow_into_malloc_1
(
4
);
break
;
case
3
:
bufptr
=
integer_overflow_into_malloc_1
(
4000000000
);
break
;
case
4
:
bufptr
=
integer_underflow
(
10
,
buf
);
break
;
case
5
:
result
=
signed_error_bypass_check
(
2048
);
break
;
case
6
:
result
=
signed_error_bypass_check
(
4000000000
);
break
;
}
}
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