NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/57689: getcwd() not overridable with -D_FORTIFY_SOURCE
>Number: 57689
>Category: lib
>Synopsis: getcwd() not overridable with -D_FORTIFY_SOURCE
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Nov 10 00:00:00 +0000 2023
>Originator: RVP
>Release: -HEAD, 10.x, 9.x
>Organization:
>Environment:
10.99.10 amd64
>Description:
getcwd() in libc is a weak symbol, but, you can't override it if compiled
with SSP & -O:
```
$ nm -D /lib/libc.so | fgrep getcwd
00000000000aea70 T __getcwd
00000000000a8ae0 T _getcwd
00000000000a8ae0 W _sys_getcwd
00000000000a8ae0 W getcwd
$ cat t.c
#include <err.h>
#include <errno.h>
#include <unistd.h>
char*
getcwd(char* buf, size_t buflen)
{
errno = ENOSYS;
return NULL;
}
int
main(void)
{
char buf[256];
if (getcwd(buf, sizeof buf) == NULL)
err(1, "getcwd failed");
return 0;
}
$ gcc -O2 -o g g.c
$ ./g
g: getcwd failed: Function not implemented
$ gcc -O2 -D_FORTIFY_SOURCE=2 -o g g.c
g.c:6:1: error: redefinition of ?getcwd?
getcwd(char* buf, size_t buflen)
^~~~~~
In file included from /usr/include/ssp/unistd.h:34:0,
from /usr/include/unistd.h:74,
from g.c:3:
/usr/include/ssp/unistd.h:45:1: note: previous definition of ?getcwd? was here
__ssp_redirect_raw(char *, getcwd, getcwd, (char *__buf, size_t __len),
^
$
```
Should be pulled up to 10.x, 9.x, 8.x.
>How-To-Repeat:
As above.
>Fix:
Ref: gnu_inline attribute description in:
https://gcc.gnu.org/onlinedocs/gcc-10.5.0/gcc/Common-Function-Attributes.html
```
--- include/ssp/ssp.h.orig 2022-06-29 12:45:25.000000000 +0000
+++ include/ssp/ssp.h 2022-06-30 23:55:56.181039331 +0000
@@ -56,7 +56,7 @@
#endif
#define __ssp_real(fun) __ssp_real_(fun)
-#define __ssp_inline static __inline __attribute__((__always_inline__))
+#define __ssp_inline extern __inline __attribute__((__always_inline__, __gnu_inline__))
#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
```
Home |
Main Index |
Thread Index |
Old Index