tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: SSP cleanup
Slightly improved version that works with the symbol redirection used in
libc and potentially other places. Also keeps the _sys_getcwd symbol in
libc for compatibility.
I'll commit this Sunday if noone objects.
Joerg
Index: src/include/ssp/ssp.h
===================================================================
--- src/include/ssp/ssp.h
+++ src/include/ssp/ssp.h
@@ -1,9 +1,9 @@
/* $NetBSD: ssp.h,v 1.8 2011/01/26 18:08:00 christos Exp $ */
/*-
- * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
@@ -38,19 +38,22 @@
# if _FORTIFY_SOURCE > 1
# define __SSP_FORTIFY_LEVEL 2
# else
# define __SSP_FORTIFY_LEVEL 1
# endif
+# else
+# define __SSP_FORTIFY_LEVEL 0
# endif
+#else
+# define __SSP_FORTIFY_LEVEL 0
#endif
-#ifndef __ssp_weak_name
-#ifdef _NAMESPACE_H_
-#define __ssp_weak_name(fun) _sys ## fun
+/* __ssp_real is used by the implementation in libc */
+#if __SSP_FORTIFY_LEVEL == 0
+#define __ssp_real(fun) fun
#else
-#define __ssp_weak_name(fun) _sys_ ## fun
-#endif
+#define __ssp_real(fun) __ssp_real_ ## fun
#endif
#define __ssp_inline static __inline __attribute__((__always_inline__))
#define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
@@ -57,24 +60,24 @@
#define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
#define __ssp_check(buf, len, bos) \
if (bos(buf) != (size_t)-1 && len > bos(buf)) \
__chk_fail()
-#define __ssp_redirect_raw(rtype, fun, args, call, bos) \
-rtype __ssp_weak_name(fun) args; \
-__ssp_inline rtype fun args; \
+#define __ssp_redirect_raw(rtype, fun, symbol, args, call, bos) \
+rtype __ssp_real(fun) args __RENAME(__STRING(symbol)); \
+__ssp_inline rtype fun args __RENAME(__ssp_protected_ ## fun); \
__ssp_inline rtype fun args { \
__ssp_check(__buf, __len, bos); \
- return __ssp_weak_name(fun) call; \
+ return __ssp_real(fun) call; \
}
#define __ssp_redirect(rtype, fun, args, call) \
- __ssp_redirect_raw(rtype, fun, args, call, __ssp_bos)
+ __ssp_redirect_raw(rtype, fun, fun, args, call, __ssp_bos)
#define __ssp_redirect0(rtype, fun, args, call) \
- __ssp_redirect_raw(rtype, fun, args, call, __ssp_bos0)
+ __ssp_redirect_raw(rtype, fun, fun, args, call, __ssp_bos0)
__BEGIN_DECLS
void __stack_chk_fail(void) __dead;
void __chk_fail(void) __dead;
__END_DECLS
#endif /* _SSP_SSP_H_ */
Index: src/lib/libc/gen/getcwd.c
===================================================================
--- src/lib/libc/gen/getcwd.c
+++ src/lib/libc/gen/getcwd.c
@@ -48,24 +48,18 @@
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ssp/ssp.h>
#include "extern.h"
#ifdef __weak_alias
-__weak_alias(getcwd,_sys_getcwd)
-__weak_alias(_getcwd,_sys_getcwd)
+__weak_alias(getcwd,_getcwd)
+__weak_alias(_sys_getcwd,_getcwd)
__weak_alias(realpath,_realpath)
-
-#undef getcwd
-#define getcwd _sys_getcwd
-#if !defined(_FORTIFY_SOURCE)
-char *_sys_getcwd(char *, size_t);
-#endif
-
#endif
/*
* char *realpath(const char *path, char resolved[MAXPATHLEN]);
*
@@ -212,11 +206,11 @@
path = q;
goto loop;
}
char *
-getcwd(char *pt, size_t size)
+__ssp_real(getcwd)(char *pt, size_t size)
{
char *npt;
/*
* If a buffer is specified, the size has to be non-zero.
Home |
Main Index |
Thread Index |
Old Index