Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
48f0fbd2
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
48f0fbd2
编写于
9月 07, 2022
作者:
G
ganlan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fortify 代码规范性整合
Signed-off-by:
N
ganlan
<
tony.gan@huawei.com
>
上级
d196b326
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
154 addition
and
151 deletion
+154
-151
libc-test/src/functionalext/fortify/fcntl.c
libc-test/src/functionalext/fortify/fcntl.c
+8
-8
libc-test/src/functionalext/fortify/poll.c
libc-test/src/functionalext/fortify/poll.c
+3
-3
libc-test/src/functionalext/fortify/socket.c
libc-test/src/functionalext/fortify/socket.c
+4
-4
porting/linux/user/include/fortify/fcntl.h
porting/linux/user/include/fortify/fcntl.h
+21
-21
porting/linux/user/include/fortify/fortify.h
porting/linux/user/include/fortify/fortify.h
+14
-11
porting/linux/user/include/fortify/poll.h
porting/linux/user/include/fortify/poll.h
+10
-10
porting/linux/user/include/fortify/stat.h
porting/linux/user/include/fortify/stat.h
+2
-2
porting/linux/user/include/fortify/stdio.h
porting/linux/user/include/fortify/stdio.h
+9
-9
porting/linux/user/include/fortify/string.h
porting/linux/user/include/fortify/string.h
+37
-37
porting/linux/user/src/fortify/fortify.c
porting/linux/user/src/fortify/fortify.c
+46
-46
未找到文件。
libc-test/src/functionalext/fortify/fcntl.c
浏览文件 @
48f0fbd2
...
...
@@ -48,7 +48,7 @@ static void open_0020(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_CREAT
;
// Fool the compiler.
int
flags
=
O_CREAT
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -82,7 +82,7 @@ static void open_0030(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_TMPFILE
;
// Fool the compiler.
int
flags
=
O_TMPFILE
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -131,7 +131,7 @@ static void openat_0020(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_CREAT
;
// Fool the compiler.
int
flags
=
O_CREAT
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -165,7 +165,7 @@ static void openat_0030(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_TMPFILE
;
// Fool the compiler.
int
flags
=
O_TMPFILE
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -214,7 +214,7 @@ static void open64_0020(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_CREAT
;
// Fool the compiler.
int
flags
=
O_CREAT
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -248,7 +248,7 @@ static void open64_0030(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_TMPFILE
;
// Fool the compiler.
int
flags
=
O_TMPFILE
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -297,7 +297,7 @@ static void openat64_0020(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_CREAT
;
// Fool the compiler.
int
flags
=
O_CREAT
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
@@ -331,7 +331,7 @@ static void openat64_0030(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
int
flags
=
O_TMPFILE
;
// Fool the compiler.
int
flags
=
O_TMPFILE
;
int
status
;
int
pid
=
fork
();
switch
(
pid
)
{
...
...
libc-test/src/functionalext/fortify/poll.c
浏览文件 @
48f0fbd2
...
...
@@ -48,7 +48,7 @@ static void poll_0020(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
nfds_t
fd_count
=
atoi
(
"2"
);
// suppress compiler optimizations
nfds_t
fd_count
=
atoi
(
"2"
);
struct
pollfd
buf
[
1
]
=
{{
0
,
POLLIN
,
0
}};
int
status
;
...
...
@@ -58,7 +58,7 @@ static void poll_0020(void)
t_error
(
"fork failed: %s
\n
"
,
strerror
(
errno
));
break
;
case
0
:
// Set timeout to
zero to prevent waiting in poll when fortify test fails
.
// Set timeout to
0 to prevent waiting for polling if hardening tests fail
.
poll
(
buf
,
fd_count
,
0
);
exit
(
0
);
default:
...
...
@@ -100,7 +100,7 @@ static void ppoll_0020(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
nfds_t
fd_count
=
atoi
(
"2"
);
// suppress compiler optimizations
nfds_t
fd_count
=
atoi
(
"2"
);
struct
pollfd
buf
[
1
]
=
{{
0
,
POLLIN
,
0
}};
// Set timeout to zero to prevent waiting in ppoll when fortify test fails.
struct
timespec
timeout
;
...
...
libc-test/src/functionalext/fortify/socket.c
浏览文件 @
48f0fbd2
...
...
@@ -56,7 +56,7 @@ static void send_0010(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
size_t
data_len
=
atoi
(
"11"
);
// suppress compiler optimizations
size_t
data_len
=
atoi
(
"11"
);
char
buf
[
BUF_SIZE_10
];
int
status
;
int
pid
=
fork
();
...
...
@@ -91,7 +91,7 @@ static void recv_0010(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
size_t
data_len
=
atoi
(
"11"
);
// suppress compiler optimizations
size_t
data_len
=
atoi
(
"11"
);
char
buf
[
BUF_SIZE_10
];
int
status
;
int
pid
=
fork
();
...
...
@@ -153,7 +153,7 @@ static void sendto_0010(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
size_t
data_len
=
atoi
(
"11"
);
// suppress compiler optimizations
size_t
data_len
=
atoi
(
"11"
);
char
buf
[
BUF_SIZE_10
];
int
status
;
int
pid
=
fork
();
...
...
@@ -188,7 +188,7 @@ static void recvfrom_0010(void)
};
sigaction
(
SIGABRT
,
&
sigabrt
,
NULL
);
size_t
data_len
=
atoi
(
"11"
);
// suppress compiler optimizations
size_t
data_len
=
atoi
(
"11"
);
char
buf
[
BUF_SIZE_10
];
int
status
;
int
pid
=
fork
();
...
...
porting/linux/user/include/fortify/fcntl.h
浏览文件 @
48f0fbd2
...
...
@@ -30,7 +30,7 @@ int __open64_diagnose(const char*, int);
int
__openat64_diagnose
(
int
,
const
char
*
,
int
);
#endif
/*
*
These are the easiest way to call the real open even in clang FORTIFY
.
*
Even in musl FORTIFY, the following is the easiest way to call a real open
.
*/
int
__open_real
(
const
char
*
,
int
,
...)
__DIAGNOSE_RENAME
(
open
);
int
__openat_real
(
int
,
const
char
*
,
int
,
...)
__DIAGNOSE_RENAME
(
openat
);
...
...
@@ -41,84 +41,84 @@ int __openat64_real(int, const char*, int, ...) __DIAGNOSE_RENAME(openat64);
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
int
open
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
)
int
open
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
),
"'open' "
OPEN_TOO_FEW_ARGS_ERROR
)
{
#ifdef __FORTIFY_RUNTIME
return
__open_diagnose
(
path
name
,
flags
);
return
__open_diagnose
(
path
,
flags
);
#else
return
__open_real
(
path
name
,
flags
);
return
__open_real
(
path
,
flags
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int
open
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
,
unsigned
modes
)
int
open
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
,
unsigned
modes
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF
(
!
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
)
&&
modes
,
"'open' "
OPEN_USELESS_MODES_WARNING
)
{
return
__open_real
(
path
name
,
flags
,
modes
);
return
__open_real
(
path
,
flags
,
modes
);
}
__DIAGNOSE_FORTIFY_INLINE
int
openat
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
)
int
openat
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
),
"'openat' "
OPEN_TOO_FEW_ARGS_ERROR
)
{
#ifdef __FORTIFY_RUNTIME
return
__openat_diagnose
(
dirfd
,
path
name
,
flags
);
return
__openat_diagnose
(
dirfd
,
path
,
flags
);
#else
return
__openat_real
(
dirfd
,
path
name
,
flags
);
return
__openat_real
(
dirfd
,
path
,
flags
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int
openat
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
,
mode_t
modes
)
int
openat
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
,
mode_t
modes
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF
(
!
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
)
&&
modes
,
"'openat' "
OPEN_USELESS_MODES_WARNING
)
{
return
__openat_real
(
dirfd
,
path
name
,
flags
,
modes
);
return
__openat_real
(
dirfd
,
path
,
flags
,
modes
);
}
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
__DIAGNOSE_FORTIFY_INLINE
int
open64
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
)
int
open64
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
),
"'open64' "
OPEN_TOO_FEW_ARGS_ERROR
)
{
#ifdef __FORTIFY_RUNTIME
return
__open64_diagnose
(
path
name
,
flags
);
return
__open64_diagnose
(
path
,
flags
);
#else
return
__open64_real
(
path
name
,
flags
);
return
__open64_real
(
path
,
flags
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int
open64
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
,
mode_t
modes
)
int
open64
(
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
,
mode_t
modes
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF
(
!
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
)
&&
modes
,
"'open64' "
OPEN_USELESS_MODES_WARNING
)
{
return
__open64_real
(
path
name
,
flags
,
modes
);
return
__open64_real
(
path
,
flags
,
modes
);
}
__DIAGNOSE_FORTIFY_INLINE
int
openat64
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
)
int
openat64
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
),
"'openat64' "
OPEN_TOO_FEW_ARGS_ERROR
)
{
#ifdef __FORTIFY_RUNTIME
return
__openat64_diagnose
(
dirfd
,
path
name
,
flags
);
return
__openat64_diagnose
(
dirfd
,
path
,
flags
);
#else
return
__openat64_real
(
dirfd
,
path
name
,
flags
);
return
__openat64_real
(
dirfd
,
path
,
flags
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
int
openat64
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
name
,
int
flags
,
mode_t
modes
)
int
openat64
(
int
dirfd
,
const
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
path
,
int
flags
,
mode_t
modes
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_WARNING_IF
(
!
__DIAGNOSE_OPEN_MODES_USEFUL
(
flags
)
&&
modes
,
"'openat64' "
OPEN_USELESS_MODES_WARNING
)
{
return
__openat64_real
(
dirfd
,
path
name
,
flags
,
modes
);
return
__openat64_real
(
dirfd
,
path
,
flags
,
modes
);
}
#endif
...
...
porting/linux/user/include/fortify/fortify.h
浏览文件 @
48f0fbd2
...
...
@@ -82,14 +82,14 @@ extern "C" {
#define __DIAGNOSE_PASS_OBJECT_SIZE0 __DIAGNOSE_PASS_OBJECT_SIZE_N(0)
#define __DIAGNOSE_FORTIFY_UNKNOWN_SIZE ((unsigned int) -1)
/*
Intended for use in unevaluated contex
ts, e.g. diagnose_if conditions. */
/*
The following are intended for use in unevaluated environmen
ts, e.g. diagnose_if conditions. */
#define __DIAGNOSE_UNEVALUATED_LT(bos_val, val) \
((bos_val) != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE && (bos_val) < (val))
#define __DIAGNOSE_UNEVALUATED_LE(bos_val, val) \
((bos_val) != __DIAGNOSE_FORTIFY_UNKNOWN_SIZE && (bos_val) <= (val))
/*
Intended for use in evaluated contexts
. */
/*
The following acts in the context of evaluation
. */
#define __DIAGNOSE_BOS_DYNAMIC_CHECK_IMPL_AND(bos_val, op, index, cond) \
((bos_val) == __DIAGNOSE_FORTIFY_UNKNOWN_SIZE || \
(__builtin_constant_p(index) && bos_val op index && (cond)))
...
...
@@ -102,7 +102,10 @@ extern "C" {
#define __DIAGNOSE_OVERLOAD __attribute__((overloadable))
/* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
/*
* A function to prevent this function from being applied.
* Used to rename the function so that the compiler emits a call to "x".
*/
#define __DIAGNOSE_RENAME(x) __asm__(#x)
#define __DIAGNOSE_OPEN_MODES_USEFUL(flags) (((flags) & O_CREAT) || ((flags) & O_TMPFILE) == O_TMPFILE)
#define __DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE(bos_val, fds, fd_count) \
...
...
@@ -116,14 +119,14 @@ extern "C" {
!__DIAGNOSE_UNSAFE_CHK_MUL_OVERFLOW(size, count))
#define FORTIFY_RUNTIME_ERROR_PREFIX "Musl Fortify runtime error: "
#define OPEN_TOO_MANY_ARGS_ERROR "too many arguments"
#define OPEN_TOO_FEW_ARGS_ERROR "
called with O_CREAT or O_TMPFILE, but missing mode
"
#define OPEN_USELESS_MODES_WARNING "ha
s superfluous mode bits; missing O_CREAT?
"
#define CALLED_WITH_STRING_BIGGER_BUFFER "called with
string bigger than
buffer"
#define FD_COUNT_LARGE_GIVEN_BUFFER "fd_count is
larg
er than the given buffer"
#define CALLED_WITH_SIZE_BIGGER_BUFFER "called with
size bigger than
buffer"
#define OUTPUT_PARAMETER_BYTES "
output parameter must be NULL or a pointer to a
buffer with >= FORTIFY_PATH_MAX bytes"
#define SIZE_LARGER_THEN_DESTINATION_BUFFER "
size is larger than the destination
buffer"
#define OPEN_TOO_MANY_ARGS_ERROR "
There are
too many arguments"
#define OPEN_TOO_FEW_ARGS_ERROR "
invoking with O_CREAT or O_TMPFILE, but missing pattern.
"
#define OPEN_USELESS_MODES_WARNING "ha
ving redundant mode bits; but missing O_CREAT.
"
#define CALLED_WITH_STRING_BIGGER_BUFFER "called with
a string larger than the
buffer"
#define FD_COUNT_LARGE_GIVEN_BUFFER "fd_count is
great
er than the given buffer"
#define CALLED_WITH_SIZE_BIGGER_BUFFER "called with
bigger size than the
buffer"
#define OUTPUT_PARAMETER_BYTES "
the output parameter must be nullptr or a pointer to the
buffer with >= FORTIFY_PATH_MAX bytes"
#define SIZE_LARGER_THEN_DESTINATION_BUFFER "
the size is greater than the target
buffer"
void
__fortify_error
(
const
char
*
info
,
...);
...
...
porting/linux/user/include/fortify/poll.h
浏览文件 @
48f0fbd2
...
...
@@ -31,37 +31,37 @@ int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*,
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
int
poll
(
struct
pollfd
*
const
fds
__DIAGNOSE_PASS_OBJECT_SIZE
,
nfds_t
fd_
c
ount
,
int
timeout
)
int
poll
(
struct
pollfd
*
const
fds
__DIAGNOSE_PASS_OBJECT_SIZE
,
nfds_t
fd_
am
ount
,
int
timeout
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
fds
),
sizeof
(
*
fds
)
*
fd_
c
ount
),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
fds
),
sizeof
(
*
fds
)
*
fd_
am
ount
),
"in call to 'poll', "
FD_COUNT_LARGE_GIVEN_BUFFER
)
{
#ifdef __FORTIFY_RUNTIME
size_t
bos_fds
=
__DIAGNOSE_BOS
(
fds
);
if
(
!
__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE
(
bos_fds
,
fds
,
fd_
c
ount
))
{
return
__poll_diagnose
(
fds
,
fd_
c
ount
,
timeout
,
bos_fds
);
if
(
!
__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE
(
bos_fds
,
fds
,
fd_
am
ount
))
{
return
__poll_diagnose
(
fds
,
fd_
am
ount
,
timeout
,
bos_fds
);
}
#endif
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
poll
)(
fds
,
fd_
c
ount
,
timeout
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
poll
)(
fds
,
fd_
am
ount
,
timeout
);
}
#ifdef _GNU_SOURCE
__DIAGNOSE_FORTIFY_INLINE
int
ppoll
(
struct
pollfd
*
const
fds
__DIAGNOSE_PASS_OBJECT_SIZE
,
nfds_t
fd_
c
ount
,
int
ppoll
(
struct
pollfd
*
const
fds
__DIAGNOSE_PASS_OBJECT_SIZE
,
nfds_t
fd_
am
ount
,
const
struct
timespec
*
timeout
,
const
sigset_t
*
mask
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
fds
),
sizeof
(
*
fds
)
*
fd_
c
ount
),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
fds
),
sizeof
(
*
fds
)
*
fd_
am
ount
),
"in call to 'ppoll', "
FD_COUNT_LARGE_GIVEN_BUFFER
)
{
#ifdef __FORTIFY_RUNTIME
size_t
bos_fds
=
__DIAGNOSE_BOS
(
fds
);
if
(
!
__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE
(
bos_fds
,
fds
,
fd_
c
ount
))
{
return
__ppoll_chk
(
fds
,
fd_
c
ount
,
timeout
,
mask
,
bos_fds
);
if
(
!
__DIAGNOSE_BOS_FD_COUNT_TRIVIALLY_SAFE
(
bos_fds
,
fds
,
fd_
am
ount
))
{
return
__ppoll_chk
(
fds
,
fd_
am
ount
,
timeout
,
mask
,
bos_fds
);
}
#endif
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
ppoll
)(
fds
,
fd_
c
ount
,
timeout
,
mask
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
ppoll
)(
fds
,
fd_
am
ount
,
timeout
,
mask
);
}
#endif
...
...
porting/linux/user/include/fortify/stat.h
浏览文件 @
48f0fbd2
...
...
@@ -27,12 +27,12 @@ mode_t __umask_diagnose(mode_t);
mode_t
__umask_real
(
mode_t
mode
)
__DIAGNOSE_RENAME
(
umask
);
#ifdef __FORTIFY_COMPILATION
/*
Abuse enable_if to make this an o
verload of umask. */
/*
O
verload of umask. */
__DIAGNOSE_FORTIFY_INLINE
mode_t
umask
(
mode_t
mode
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ENABLE_IF
(
1
,
""
)
__DIAGNOSE_ERROR_IF
(
mode
&
~
0777
,
"'umask'
called with
invalid mode"
)
__DIAGNOSE_ERROR_IF
(
mode
&
~
0777
,
"'umask'
was called in
invalid mode"
)
{
#ifdef __FORTIFY_RUNTIME
return
__umask_diagnose
(
mode
);
...
...
porting/linux/user/include/fortify/stdio.h
浏览文件 @
48f0fbd2
...
...
@@ -77,7 +77,7 @@ __DIAGNOSE_ERROR_IF(__DIAGNOSE_UNEVALUATED_LT(__DIAGNOSE_BOS0(buf), size * count
__DIAGNOSE_FORTIFY_INLINE
char
*
fgets
(
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
dest
,
int
size
,
FILE
*
stream
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
size
<
0
,
"in call to 'fgets', size should not be
negative
"
)
__DIAGNOSE_ERROR_IF
(
size
<
0
,
"in call to 'fgets', size should not be
less than 0
"
)
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
dest
),
size
),
"in call to 'fgets', "
SIZE_LARGER_THEN_DESTINATION_BUFFER
)
{
...
...
@@ -111,10 +111,10 @@ __DIAGNOSE_FORTIFY_VARIADIC __DIAGNOSE_PRINTFLIKE(FORMAT_PLACE_2, VALIST_PLACE_3
int
sprintf
(
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
dest
,
const
char
*
format
,
...)
__DIAGNOSE_OVERLOAD
{
va_list
va
;
va_start
(
va
,
format
);
int
result
=
__builtin___vsprintf_chk
(
dest
,
0
,
__DIAGNOSE_BOS
(
dest
),
format
,
va
);
va_end
(
va
);
va_list
va
_l
;
va_start
(
va
_l
,
format
);
int
result
=
__builtin___vsprintf_chk
(
dest
,
0
,
__DIAGNOSE_BOS
(
dest
),
format
,
va
_l
);
va_end
(
va
_l
);
return
result
;
}
...
...
@@ -122,10 +122,10 @@ __DIAGNOSE_FORTIFY_VARIADIC __DIAGNOSE_PRINTFLIKE(FORMAT_PLACE_3, VALIST_PLACE_4
int
snprintf
(
char
*
const
__DIAGNOSE_PASS_OBJECT_SIZE
dest
,
size_t
size
,
const
char
*
format
,
...)
__DIAGNOSE_OVERLOAD
{
va_list
va
;
va_start
(
va
,
format
);
int
result
=
__builtin___vsnprintf_chk
(
dest
,
size
,
0
,
__DIAGNOSE_BOS
(
dest
),
format
,
va
);
va_end
(
va
);
va_list
va
_l
;
va_start
(
va
_l
,
format
);
int
result
=
__builtin___vsnprintf_chk
(
dest
,
size
,
0
,
__DIAGNOSE_BOS
(
dest
),
format
,
va
_l
);
va_end
(
va
_l
);
return
result
;
}
...
...
porting/linux/user/include/fortify/string.h
浏览文件 @
48f0fbd2
...
...
@@ -33,132 +33,132 @@ size_t __strlen_chk(const char* s, size_t s_len);
#ifdef __FORTIFY_COMPILATION
__DIAGNOSE_FORTIFY_INLINE
char
*
strcpy
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
)
char
*
strcpy
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LE
(
__DIAGNOSE_BOS
(
dst
),
__builtin_strlen
(
src
)),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LE
(
__DIAGNOSE_BOS
(
d
e
st
),
__builtin_strlen
(
src
)),
"'strcpy' "
CALLED_WITH_STRING_BIGGER_BUFFER
)
{
#ifdef __FORTIFY_RUNTIME
return
__builtin___strcpy_chk
(
d
st
,
src
,
__DIAGNOSE_BOS
(
d
st
));
return
__builtin___strcpy_chk
(
d
est
,
src
,
__DIAGNOSE_BOS
(
de
st
));
#else
return
__builtin_strcpy
(
dst
,
src
);
return
__builtin_strcpy
(
d
e
st
,
src
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
char
*
stpcpy
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
)
char
*
stpcpy
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LE
(
__DIAGNOSE_BOS
(
dst
),
__builtin_strlen
(
src
)),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LE
(
__DIAGNOSE_BOS
(
d
e
st
),
__builtin_strlen
(
src
)),
"'stpcpy' "
CALLED_WITH_STRING_BIGGER_BUFFER
)
{
#ifdef __FORTIFY_RUNTIME
return
__builtin___stpcpy_chk
(
d
st
,
src
,
__DIAGNOSE_BOS
(
d
st
));
return
__builtin___stpcpy_chk
(
d
est
,
src
,
__DIAGNOSE_BOS
(
de
st
));
#else
return
__builtin_stpcpy
(
dst
,
src
);
return
__builtin_stpcpy
(
d
e
st
,
src
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
void
*
memmove
(
void
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE0
,
const
void
*
src
,
size_t
len
)
void
*
memmove
(
void
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE0
,
const
void
*
src
,
size_t
len
)
__DIAGNOSE_OVERLOAD
{
#ifdef __FORTIFY_RUNTIME
return
__builtin___memmove_chk
(
d
st
,
src
,
len
,
__DIAGNOSE_BOS
(
d
st
));
return
__builtin___memmove_chk
(
d
est
,
src
,
len
,
__DIAGNOSE_BOS
(
de
st
));
#else
return
__builtin_memmove
(
dst
,
src
,
len
);
return
__builtin_memmove
(
d
e
st
,
src
,
len
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
void
*
mempcpy
(
void
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
void
*
src
,
size_t
copy_amount
)
void
*
mempcpy
(
void
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
void
*
src
,
size_t
copy_amount
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS0
(
dst
),
copy_amount
),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS0
(
d
e
st
),
copy_amount
),
"'mempcpy' "
CALLED_WITH_STRING_BIGGER_BUFFER
)
{
#ifdef __FORTIFY_RUNTIME
return
__builtin___mempcpy_chk
(
d
st
,
src
,
copy_amount
,
__DIAGNOSE_BOS0
(
d
st
));
return
__builtin___mempcpy_chk
(
d
est
,
src
,
copy_amount
,
__DIAGNOSE_BOS0
(
de
st
));
#else
return
__builtin_mempcpy
(
dst
,
src
,
copy_amount
);
return
__builtin_mempcpy
(
d
e
st
,
src
,
copy_amount
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
char
*
strcat
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
)
char
*
strcat
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LE
(
__DIAGNOSE_BOS
(
dst
),
__builtin_strlen
(
src
)),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LE
(
__DIAGNOSE_BOS
(
d
e
st
),
__builtin_strlen
(
src
)),
"'strcat' "
CALLED_WITH_STRING_BIGGER_BUFFER
)
{
#ifdef __FORTIFY_RUNTIME
return
__builtin___strcat_chk
(
d
st
,
src
,
__DIAGNOSE_BOS
(
d
st
));
return
__builtin___strcat_chk
(
d
est
,
src
,
__DIAGNOSE_BOS
(
de
st
));
#else
return
__builtin_strcat
(
dst
,
src
);
return
__builtin_strcat
(
d
e
st
,
src
);
#endif
}
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
char
*
strncat
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
,
size_t
n
)
char
*
strncat
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
,
size_t
n
)
__DIAGNOSE_OVERLOAD
{
return
__builtin___strncat_chk
(
d
st
,
src
,
n
,
__DIAGNOSE_BOS
(
d
st
));
return
__builtin___strncat_chk
(
d
est
,
src
,
n
,
__DIAGNOSE_BOS
(
de
st
));
}
#endif
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
char
*
stpncpy
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
char
*
stpncpy
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
const
src
__DIAGNOSE_PASS_OBJECT_SIZE
,
size_t
n
)
__DIAGNOSE_OVERLOAD
{
size_t
bos_d
st
=
__DIAGNOSE_BOS
(
d
st
);
return
__builtin___stpncpy_chk
(
d
st
,
src
,
n
,
bos_d
st
);
size_t
bos_d
est
=
__DIAGNOSE_BOS
(
de
st
);
return
__builtin___stpncpy_chk
(
d
est
,
src
,
n
,
bos_de
st
);
}
#endif
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
char
*
strncpy
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
char
*
strncpy
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
const
src
__DIAGNOSE_PASS_OBJECT_SIZE
,
size_t
n
)
__DIAGNOSE_OVERLOAD
{
size_t
bos_d
st
=
__DIAGNOSE_BOS
(
d
st
);
return
__builtin___strncpy_chk
(
d
st
,
src
,
n
,
bos_d
st
);
size_t
bos_d
est
=
__DIAGNOSE_BOS
(
de
st
);
return
__builtin___strncpy_chk
(
d
est
,
src
,
n
,
bos_de
st
);
}
#endif
#ifdef __FORTIFY_RUNTIME
__DIAGNOSE_FORTIFY_INLINE
void
*
memcpy
(
void
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE0
,
const
void
*
src
,
size_t
copy_amount
)
void
*
memcpy
(
void
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE0
,
const
void
*
src
,
size_t
copy_amount
)
__DIAGNOSE_OVERLOAD
{
return
__builtin___memcpy_chk
(
d
st
,
src
,
copy_amount
,
__DIAGNOSE_BOS0
(
d
st
));
return
__builtin___memcpy_chk
(
d
est
,
src
,
copy_amount
,
__DIAGNOSE_BOS0
(
de
st
));
}
#endif
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
__DIAGNOSE_FORTIFY_INLINE
size_t
strlcpy
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
,
size_t
size
)
size_t
strlcpy
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
,
size_t
size
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
dst
),
size
),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
d
e
st
),
size
),
"'strlcpy' called with size bigger than buffer"
)
{
#ifdef __FORTIFY_RUNTIME
return
__strlcpy_diagnose
(
d
st
,
src
,
size
,
__DIAGNOSE_BOS
(
d
st
));
return
__strlcpy_diagnose
(
d
est
,
src
,
size
,
__DIAGNOSE_BOS
(
de
st
));
#else
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcpy
)(
dst
,
src
,
size
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcpy
)(
d
e
st
,
src
,
size
);
#endif
}
__DIAGNOSE_FORTIFY_INLINE
size_t
strlcat
(
char
*
const
dst
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
,
size_t
size
)
size_t
strlcat
(
char
*
const
d
e
st
__DIAGNOSE_PASS_OBJECT_SIZE
,
const
char
*
src
,
size_t
size
)
__DIAGNOSE_OVERLOAD
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
dst
),
size
),
__DIAGNOSE_ERROR_IF
(
__DIAGNOSE_UNEVALUATED_LT
(
__DIAGNOSE_BOS
(
d
e
st
),
size
),
"'strlcat' called with size bigger than buffer"
)
{
#ifdef __FORTIFY_RUNTIME
return
__strlcat_diagnose
(
d
st
,
src
,
size
,
__DIAGNOSE_BOS
(
d
st
));
return
__strlcat_diagnose
(
d
est
,
src
,
size
,
__DIAGNOSE_BOS
(
de
st
));
#else
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcat
)(
dst
,
src
,
size
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcat
)(
d
e
st
,
src
,
size
);
#endif
}
#endif // defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
...
...
porting/linux/user/src/fortify/fortify.c
浏览文件 @
48f0fbd2
...
...
@@ -119,7 +119,7 @@ static inline void __diagnose_buffer_access(const char* fn, const char* action,
size_t
claim
,
size_t
actual
)
{
if
(
__DIAGNOSE_PREDICT_FALSE
(
claim
>
actual
))
{
__fortify_error
(
"%s:
prevente
d %zu-byte %s %zu-byte buffer
\n
"
,
fn
,
claim
,
action
,
actual
);
__fortify_error
(
"%s:
avoi
d %zu-byte %s %zu-byte buffer
\n
"
,
fn
,
claim
,
action
,
actual
);
}
}
...
...
@@ -157,8 +157,8 @@ mode_t __umask_diagnose(mode_t mode)
return
__umask_real
(
mode
);
}
// Runtime implementation of
string related interface
//
(used directly by the compiler, not in a header file)
.
// Runtime implementation of
the string-dependent interface.
//
Used directly by the compiler, not in a header file
.
static
inline
void
__diagnose_count
(
const
char
*
fn
,
const
char
*
identifier
,
size_t
value
)
{
if
(
__DIAGNOSE_PREDICT_FALSE
(
value
>
LONG_MAX
))
{
...
...
@@ -170,59 +170,59 @@ size_t __strlen_chk(const char* s, size_t s_len)
{
size_t
ret
=
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlen
)(
s
);
if
(
__DIAGNOSE_PREDICT_FALSE
(
ret
>=
s_len
))
{
__fortify_error
(
"strlen: d
etected read past
end of buffer
\n
"
);
__fortify_error
(
"strlen: d
iagnose read exceed
end of buffer
\n
"
);
}
return
ret
;
}
char
*
__strncat_chk
(
char
*
dst
,
const
char
*
src
,
size_t
len
,
size_t
dst_buf_size
)
char
*
__strncat_chk
(
char
*
d
e
st
,
const
char
*
src
,
size_t
len
,
size_t
dst_buf_size
)
{
size_t
src_len
=
strlen
(
src
)
+
strlen
(
dst
);
size_t
src_len
=
strlen
(
src
)
+
strlen
(
d
e
st
);
__diagnose_buffer_access
(
"strncat"
,
"write into"
,
src_len
,
dst_buf_size
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strncat
)(
dst
,
src
,
len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strncat
)(
d
e
st
,
src
,
len
);
}
char
*
__strcat_chk
(
char
*
dst
,
const
char
*
src
,
size_t
dst_buf_size
)
char
*
__strcat_chk
(
char
*
d
e
st
,
const
char
*
src
,
size_t
dst_buf_size
)
{
size_t
src_len
=
strlen
(
src
)
+
strlen
(
dst
);
size_t
src_len
=
strlen
(
src
)
+
strlen
(
d
e
st
);
__diagnose_buffer_access
(
"strcat"
,
"write into"
,
src_len
,
dst_buf_size
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strcat
)(
dst
,
src
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strcat
)(
d
e
st
,
src
);
}
char
*
__strcpy_chk
(
char
*
dst
,
const
char
*
src
,
size_t
dst_len
)
char
*
__strcpy_chk
(
char
*
d
e
st
,
const
char
*
src
,
size_t
dst_len
)
{
size_t
src_len
=
strlen
(
src
)
+
1
;
__diagnose_buffer_access
(
"strcpy"
,
"write into"
,
src_len
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strcpy
)(
dst
,
src
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strcpy
)(
d
e
st
,
src
);
}
void
*
__memmove_chk
(
void
*
dst
,
const
void
*
src
,
size_t
len
,
size_t
dst_len
)
void
*
__memmove_chk
(
void
*
d
e
st
,
const
void
*
src
,
size_t
len
,
size_t
dst_len
)
{
__diagnose_buffer_access
(
"memmove"
,
"write into"
,
len
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memmove
)(
dst
,
src
,
len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memmove
)(
d
e
st
,
src
,
len
);
}
void
*
__memcpy_chk
(
void
*
dst
,
const
void
*
src
,
size_t
count
,
size_t
dst_len
)
void
*
__memcpy_chk
(
void
*
d
e
st
,
const
void
*
src
,
size_t
count
,
size_t
dst_len
)
{
__diagnose_count
(
"memcpy"
,
"count"
,
count
);
__diagnose_buffer_access
(
"memcpy"
,
"write into"
,
count
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memcpy
)(
dst
,
src
,
count
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memcpy
)(
d
e
st
,
src
,
count
);
}
#ifdef _GNU_SOURCE
void
*
__mempcpy_chk
(
void
*
dst
,
const
void
*
src
,
size_t
count
,
size_t
dst_len
)
void
*
__mempcpy_chk
(
void
*
d
e
st
,
const
void
*
src
,
size_t
count
,
size_t
dst_len
)
{
__diagnose_count
(
"mempcpy"
,
"count"
,
count
);
__diagnose_buffer_access
(
"mempcpy"
,
"write into"
,
count
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
mempcpy
)(
dst
,
src
,
count
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
mempcpy
)(
d
e
st
,
src
,
count
);
}
#endif
char
*
__stpcpy_chk
(
char
*
dst
,
const
char
*
src
,
size_t
dst_len
)
char
*
__stpcpy_chk
(
char
*
d
e
st
,
const
char
*
src
,
size_t
dst_len
)
{
size_t
src_len
=
strlen
(
src
);
__diagnose_buffer_access
(
"stpcpy"
,
"write into"
,
src_len
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
stpcpy
)(
dst
,
src
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
stpcpy
)(
d
e
st
,
src
);
}
void
*
__memchr_diagnose
(
const
void
*
s
,
int
c
,
size_t
n
,
size_t
actual_size
)
...
...
@@ -232,56 +232,56 @@ void* __memchr_diagnose(const void* s, int c, size_t n, size_t actual_size)
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memchr
)(
const_cast_s
,
c
,
n
);
}
char
*
__stpncpy_chk
(
char
*
dst
,
const
char
*
src
,
size_t
len
,
size_t
dst_len
)
char
*
__stpncpy_chk
(
char
*
d
e
st
,
const
char
*
src
,
size_t
len
,
size_t
dst_len
)
{
__diagnose_buffer_access
(
"stpncpy"
,
"write into"
,
len
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
stpncpy
)(
dst
,
src
,
len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
stpncpy
)(
d
e
st
,
src
,
len
);
}
char
*
__strncpy_chk
(
char
*
dst
,
const
char
*
src
,
size_t
len
,
size_t
dst_len
)
char
*
__strncpy_chk
(
char
*
d
e
st
,
const
char
*
src
,
size_t
len
,
size_t
dst_len
)
{
__diagnose_buffer_access
(
"strncpy"
,
"write into"
,
len
,
dst_len
);
if
(
len
!=
0
)
{
char
*
d
=
dst
;
char
*
d
=
d
e
st
;
const
char
*
s
=
src
;
size_t
src_len
=
strlen
(
src
);
do
{
size_t
s_copy_len
=
(
size_t
)(
s
-
src
);
if
(
__DIAGNOSE_PREDICT_FALSE
(
s_copy_len
>=
src_len
))
{
__fortify_error
(
"strncpy: d
etected read past
end of %zu-byte buffer
\n
"
,
src_len
);
__fortify_error
(
"strncpy: d
iagnose read exceed
end of %zu-byte buffer
\n
"
,
src_len
);
}
}
while
(
--
len
!=
0
);
}
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strncpy
)(
dst
,
src
,
len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strncpy
)(
d
e
st
,
src
,
len
);
}
void
*
__memset_chk
(
void
*
dst
,
int
byte
,
size_t
count
,
size_t
dst_len
)
void
*
__memset_chk
(
void
*
d
e
st
,
int
byte
,
size_t
count
,
size_t
dst_len
)
{
__diagnose_count
(
"memset"
,
"count"
,
count
);
__diagnose_buffer_access
(
"memset"
,
"write into"
,
count
,
dst_len
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memset
)(
dst
,
byte
,
count
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
memset
)(
d
e
st
,
byte
,
count
);
}
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
size_t
__strlcpy_diagnose
(
char
*
dst
,
const
char
*
src
,
size_t
__strlcpy_diagnose
(
char
*
d
e
st
,
const
char
*
src
,
size_t
supplied_size
,
size_t
dst_len_from_compiler
)
{
__diagnose_buffer_access
(
"strlcpy"
,
"write into"
,
supplied_size
,
dst_len_from_compiler
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcpy
)(
dst
,
src
,
supplied_size
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcpy
)(
d
e
st
,
src
,
supplied_size
);
}
size_t
__strlcat_diagnose
(
char
*
dst
,
const
char
*
src
,
size_t
__strlcat_diagnose
(
char
*
d
e
st
,
const
char
*
src
,
size_t
supplied_size
,
size_t
dst_len_from_compiler
)
{
__diagnose_buffer_access
(
"strlcat"
,
"write into"
,
supplied_size
,
dst_len_from_compiler
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcat
)(
dst
,
src
,
supplied_size
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strlcat
)(
d
e
st
,
src
,
supplied_size
);
}
#endif
char
*
__strchr_diagnose
(
const
char
*
s
,
int
c
,
size_t
s_len
)
{
if
(
s_len
==
0
)
{
__fortify_error
(
"strchr:
prevented read past
end of buffer
\n
"
);
__fortify_error
(
"strchr:
avoid read exceed
end of buffer
\n
"
);
}
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strchr
)(
s
,
c
);
}
...
...
@@ -289,7 +289,7 @@ char* __strchr_diagnose(const char *s, int c, size_t s_len)
char
*
__strrchr_diagnose
(
const
char
*
s
,
int
c
,
size_t
s_len
)
{
if
(
s_len
==
0
)
{
__fortify_error
(
"strrchr:
prevented read past
end of buffer
\n
"
);
__fortify_error
(
"strrchr:
avoid read exceed
end of buffer
\n
"
);
}
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
strrchr
)(
s
,
c
);
}
...
...
@@ -373,49 +373,49 @@ size_t __fwrite_chk(const void* buf, size_t size, size_t count, FILE* stream, si
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
fwrite
)(
buf
,
size
,
count
,
stream
);
}
char
*
__fgets_chk
(
char
*
dst
,
int
supplied_size
,
FILE
*
stream
,
size_t
dst_len_from_compiler
)
char
*
__fgets_chk
(
char
*
d
e
st
,
int
supplied_size
,
FILE
*
stream
,
size_t
dst_len_from_compiler
)
{
__diagnose_buffer_access
(
"fgets"
,
"write into"
,
supplied_size
,
dst_len_from_compiler
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
fgets
)(
dst
,
supplied_size
,
stream
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
fgets
)(
d
e
st
,
supplied_size
,
stream
);
}
int
__vsnprintf_chk
(
char
*
dst
,
size_t
supplied_size
,
int
flags
,
int
__vsnprintf_chk
(
char
*
d
e
st
,
size_t
supplied_size
,
int
flags
,
size_t
dst_len_from_compiler
,
const
char
*
format
,
va_list
va
)
{
__diagnose_buffer_access
(
"vsnprintf"
,
"write into"
,
supplied_size
,
dst_len_from_compiler
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
vsnprintf
)(
dst
,
supplied_size
,
format
,
va
);
return
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
vsnprintf
)(
d
e
st
,
supplied_size
,
format
,
va
);
}
int
__vsprintf_chk
(
char
*
dst
,
int
flags
,
int
__vsprintf_chk
(
char
*
d
e
st
,
int
flags
,
size_t
dst_len_from_compiler
,
const
char
*
format
,
va_list
va
)
{
// The compiler
uses SIZE_MAX to mean "no idea", but our vsnprintf rejects sizes that larg
e.
int
result
=
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
vsnprintf
)(
dst
,
// The compiler
has SIZE_MAX, But vsnprintf cannot use such a large siz
e.
int
result
=
__DIAGNOSE_CALL_BYPASSING_FORTIFY
(
vsnprintf
)(
d
e
st
,
dst_len_from_compiler
==
SIZE_MAX
?
SSIZE_MAX
:
dst_len_from_compiler
,
format
,
va
);
//
Try to catch failures after the fact..
.
//
Attempts to find out after the fact fail
.
__diagnose_buffer_access
(
"vsprintf"
,
"write into"
,
result
+
1
,
dst_len_from_compiler
);
return
result
;
}
#undef SSIZE_MAX
#undef SIZE_MAX
int
__snprintf_chk
(
char
*
dst
,
size_t
supplied_size
,
int
flags
,
int
__snprintf_chk
(
char
*
d
e
st
,
size_t
supplied_size
,
int
flags
,
size_t
dst_len_from_compiler
,
const
char
*
format
,
...)
{
va_list
va
;
va_start
(
va
,
format
);
int
result
=
__vsnprintf_chk
(
dst
,
supplied_size
,
flags
,
dst_len_from_compiler
,
format
,
va
);
int
result
=
__vsnprintf_chk
(
d
e
st
,
supplied_size
,
flags
,
dst_len_from_compiler
,
format
,
va
);
va_end
(
va
);
return
result
;
}
int
__sprintf_chk
(
char
*
dst
,
int
flags
,
size_t
dst_len_from_compiler
,
const
char
*
format
,
...)
int
__sprintf_chk
(
char
*
d
e
st
,
int
flags
,
size_t
dst_len_from_compiler
,
const
char
*
format
,
...)
{
va_list
va
;
va_start
(
va
,
format
);
int
result
=
__vsprintf_chk
(
dst
,
flags
,
dst_len_from_compiler
,
format
,
va
);
int
result
=
__vsprintf_chk
(
d
e
st
,
flags
,
dst_len_from_compiler
,
format
,
va
);
va_end
(
va
);
return
result
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录