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
433dbb0f
Commit
433dbb0f
authored
13 years ago
by
an7s
Browse files
Options
Downloads
Patches
Plain Diff
Multiply examples
parent
31bea254
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitattributes
+2
-0
2 additions, 0 deletions
.gitattributes
examples/integerbug.c
+49
-5
49 additions, 5 deletions
examples/integerbug.c
examples/mul/generate_cprogs.sh
+53
-0
53 additions, 0 deletions
examples/mul/generate_cprogs.sh
examples/mul/mul.ctmpl
+21
-0
21 additions, 0 deletions
examples/mul/mul.ctmpl
with
125 additions
and
5 deletions
.gitattributes
+
2
−
0
View file @
433dbb0f
...
@@ -145,6 +145,8 @@ examples/Makefile -text
...
@@ -145,6 +145,8 @@ examples/Makefile -text
examples/dumbledore.c -text
examples/dumbledore.c -text
examples/dumbledore_cmd.c -text
examples/dumbledore_cmd.c -text
examples/integerbug.c -text
examples/integerbug.c -text
examples/mul/generate_cprogs.sh -text
examples/mul/mul.ctmpl -text
examples/overflow1.c -text
examples/overflow1.c -text
examples/test1.c -text
examples/test1.c -text
libIRDB/Makefile -text
libIRDB/Makefile -text
...
...
This diff is collapsed.
Click to expand it.
examples/integerbug.c
+
49
−
5
View file @
433dbb0f
#define MAX_INT 2147483647
#include
<stdio.h>
#define MAX_UINT 4294967295
#define INT_MAX 2147483647
#define UINT_MAX 4294967295
int
int_fussy_overflow
(
int
x
,
int
y
)
int
int_fussy_overflow
(
int
x
,
int
y
)
{
{
...
@@ -58,6 +60,23 @@ char* integer_underflow(unsigned len, char *src)
...
@@ -58,6 +60,23 @@ char* integer_underflow(unsigned len, char *src)
return
comm
;
return
comm
;
}
}
#define BUFF_SIZE 10
// if len is < 0, this will bypass the check
// which will result in an overflow of buf[]
char
*
sign_error_buffer_overflow
(
int
len
,
char
*
src
)
{
printf
(
"sign_error_buffer_overflow(): %d
\n
"
,
len
);
char
buf
[
BUFF_SIZE
];
if
(
len
<
BUFF_SIZE
)
{
printf
(
"Copying %u bytes into buffer of size %u
\n
"
,
len
,
BUFF_SIZE
);
return
memcpy
(
buf
,
src
,
len
);
}
else
{
return
NULL
;
}
}
char
*
signed_error
(
int
size
)
char
*
signed_error
(
int
size
)
{
{
printf
(
"signed_error(): %d
\n
"
,
size
);
printf
(
"signed_error(): %d
\n
"
,
size
);
...
@@ -87,6 +106,24 @@ char* trunc_error(unsigned size, int numElements)
...
@@ -87,6 +106,24 @@ char* trunc_error(unsigned size, int numElements)
return
malloc
(
len
*
numElements
);
return
malloc
(
len
*
numElements
);
}
}
short
sign_extend_char_short
(
char
c
)
{
short
s
;
return
s
=
c
;
}
short
sign_extend_char_long
(
char
c
)
{
long
l
;
return
l
=
c
;
}
short
sign_extend_short_long
(
short
s
)
{
long
l
;
return
l
=
s
;
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
selector
=
0
;
int
selector
=
0
;
...
@@ -109,9 +146,10 @@ int main(int argc, char **argv)
...
@@ -109,9 +146,10 @@ int main(int argc, char **argv)
bufptr
=
integer_underflow
(
10
,
buf
);
bufptr
=
integer_underflow
(
10
,
buf
);
result
=
signed_error_bypass_check
(
10
);
result
=
signed_error_bypass_check
(
10
);
bufptr
=
trunc_error
(
10
,
10
);
bufptr
=
trunc_error
(
10
,
10
);
signed_overflow
(
2
,
3
);
break
;
break
;
// bad inputs here
//
"
bad
"
inputs here
case
1
:
case
1
:
bufptr
=
integer_overflow_into_malloc_2
(
2000000000
,
4
);
bufptr
=
integer_overflow_into_malloc_2
(
2000000000
,
4
);
break
;
break
;
...
@@ -128,10 +166,16 @@ int main(int argc, char **argv)
...
@@ -128,10 +166,16 @@ int main(int argc, char **argv)
bufptr
=
trunc_error
(
65000
,
10
);
bufptr
=
trunc_error
(
65000
,
10
);
break
;
break
;
case
6
:
case
6
:
int_fussy_overflow
(
MAX_
INT
,
MAX
_
INT
);
int_fussy_overflow
(
INT
_
MAX
,
INT
_MAX
);
break
;
break
;
case
7
:
case
7
:
signed_overflow
(
MAX_INT
,
MAX_INT
);
signed_overflow
(
INT_MAX
,
INT_MAX
);
break
;
case
8
:
signed_overflow
(
INT_MAX
,
INT_MAX
);
break
;
case
9
:
sign_error_buffer_overflow
(
-
1
,
buf
);
break
;
break
;
}
}
}
}
This diff is collapsed.
Click to expand it.
examples/mul/generate_cprogs.sh
0 → 100755
+
53
−
0
View file @
433dbb0f
#!/bin/bash
#types="char short int long unsigned+char unsigned+short unsigned+int unsigned+long";
types
=
"int char"
create_prog
()
{
progname
=
$1
my_type1
=
$2
my_type2
=
$3
# substitute space for +
real_type1
=
`
echo
$my_type1
|
sed
"s/+/ /g"
`
real_type2
=
`
echo
$my_type2
|
sed
"s/+/ /g"
`
# substitute _ for + to get a valid C function name
name_type1
=
`
echo
$my_type1
|
sed
"s/+/_/g"
`
name_type2
=
`
echo
$my_type2
|
sed
"s/+/_/g"
`
function_name
=
"test_
${
name_type1
}
_
${
name_type2
}
"
case
$my_type1
in
"char"
)
format_specifier
=
"%c"
;;
"short"
)
format_specifier
=
"%hd"
;;
"int"
)
format_specifier
=
"%d"
;;
"long"
)
format_specifier
=
"%ld"
;;
"unsigned+char"
)
format_specifier
=
"%uc"
;;
"unsigned+short"
)
format_specifier
=
"%hu"
;;
"unsigned+int"
)
format_specifier
=
"%u"
;;
"unsigned+long"
)
format_specifier
=
"%ul"
;;
esac
# create the program.
cat
mul.ctmpl |
\
sed
"s/#FUNCTION_NAME#/
$function_name
/g"
|
\
sed
"s/#FORMAT_SPECIFIER#/
$format_specifier
/g"
|
\
sed
"s/#TYPE1#/
$real_type1
/g"
|
\
sed
"s/#TYPE2#/
$real_type2
/g"
\
>
$progname
.c
gcc
-w
$progname
.c
-o
$progname
.orig.exe
$PEASOUP_HOME
/tools/ps_analyze.sh
--step
ilr
=
off
--step
p1transform
=
off
$progname
.orig.exe
$progname
.protected.exe
}
for
type1
in
$types
do
for
type2
in
$types
do
progname_c
=
mul.
$type1
.
$type2
# actually create the .c program
create_prog
$progname_c
"
$type1
"
"
$type2
"
static_lib
done
done
This diff is collapsed.
Click to expand it.
examples/mul/mul.ctmpl
0 → 100644
+
21
−
0
View file @
433dbb0f
#TYPE1# #FUNCTION_NAME#(#TYPE1# x, #TYPE2# y)
{
#TYPE1# result = x * y;
printf("result = #FORMAT_SPECIFIER#\n", result);
return result;
}
main()
{
#TYPE1# x = 127;
#TYPE2# y = 0xFFFFFFFF;
#FUNCTION_NAME#(x, y);
x = 0x0FFFFFFF;
y = 0x0FFFFFFF;
#FUNCTION_NAME#(x, y);
x = 0x0000007F;
y = 0x0000007F;
#FUNCTION_NAME#(x, y);
}
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