Commit 89f00a2e authored by Jan Leupold's avatar Jan Leupold Committed by Jan Kiszka

lib/cobalt: Wrap __open_2/__open64_2 to support _FORTIFY_SOURCE

__open_2() and __open64_2() from glibc add runtime precondition tests for the
'oflag' parameter to the functionality of open()/open64(). They may be used when
the macro _FORTIFY_SOURCE is defined when compiling the application code. Added
these wrappers to cover those cases.

If Xenomai itself is not compiled with FORTIFY_SOURCE then the function
declarations for __open_2() and __open64_2() are not available.
__STD(__open_2(...)) will not link in this case (would be a very special
use case anyway?).
Signed-off-by: default avatarJan Leupold <leupold@rsi-elektrotechnik.de>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent b3d319ac
Pipeline #4653 passed with stage
in 30 minutes and 9 seconds
......@@ -31,6 +31,10 @@ COBALT_DECL(int, open(const char *path, int oflag, ...));
COBALT_DECL(int, open64(const char *path, int oflag, ...));
COBALT_DECL(int, __open_2(const char *path, int oflag));
COBALT_DECL(int, __open64_2(const char *path, int oflag));
COBALT_DECL(int, fcntl(int fd, int cmd, ...));
#ifdef __cplusplus
......
......@@ -54,6 +54,8 @@
--wrap mq_notify
--wrap open
--wrap open64
--wrap __open_2
--wrap __open64_2
--wrap socket
--wrap close
--wrap ioctl
......
......@@ -23,6 +23,7 @@
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <rtdm/rtdm.h>
......@@ -94,6 +95,37 @@ COBALT_IMPL(int, open64, (const char *path, int oflag, ...))
return do_open(path, oflag | O_LARGEFILE, mode);
}
COBALT_IMPL(int, __open_2, (const char *path, int oflag))
{
/* __open_2() from glibc adds a runtime precondition test for the 'oflag'
* parameter to the functionality of open(). It may be used when the macro
* _FORTIFY_SOURCE is defined when compiling the application code.
*/
if (__OPEN_NEEDS_MODE(oflag)) {
const char *msg =
"invalid open call: O_CREAT or O_TMPFILE without mode\n";
ssize_t n = __STD(write(STDERR_FILENO, msg, strlen(msg)));
(void)n;
abort();
}
return do_open(path, oflag, 0);
}
COBALT_IMPL(int, __open64_2, (const char *path, int oflag))
{
/* just like __open_2() and open64() */
if (__OPEN_NEEDS_MODE(oflag)) {
const char *msg =
"invalid open64 call: O_CREAT or O_TMPFILE without mode\n";
ssize_t n = __STD(write(STDERR_FILENO, msg, strlen(msg)));
(void)n;
abort();
}
return do_open(path, oflag | O_LARGEFILE, 0);
}
COBALT_IMPL(int, socket, (int protocol_family, int socket_type, int protocol))
{
int s;
......
......@@ -205,6 +205,18 @@ int __real_open64(const char *path, int oflag, ...)
}
#endif
#if __USE_FORTIFY_LEVEL > 0
__weak int __real___open_2(const char *path, int oflag)
{
return __open_2(path, oflag);
}
__weak int __real___open64_2(const char *path, int oflag)
{
return __open64_2(path, oflag);
}
#endif // __USE_FORTIFY_LEVEL > 0
__weak
int __real_socket(int protocol_family, int socket_type, int protocol)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment