Files
bpfire/src/patches/libsafe-alpha.diff

233 lines
5.3 KiB
Diff

--- libsafe-2.0-16-orig/src/intercept.c 2003-03-15 16:02:12.000000000 +0100
+++ libsafe-2.0-16/src/intercept.c 2003-03-15 16:12:22.000000000 +0100
@@ -165,7 +165,8 @@
*/
char *strcpy(char *dest, const char *src)
{
- size_t max_size, len;
+ uint max_size;
+ size_t len;
if (!real_memcpy)
real_memcpy = (memcpy_t) getLibraryFunction("memcpy");
@@ -196,7 +197,8 @@
char *strncpy(char *dest, const char *src, size_t n)
{
- size_t max_size, len;
+ uint max_size;
+ size_t len;
if (!real_strncpy)
real_strncpy = (strncpy_t) getLibraryFunction("strncpy");
@@ -219,7 +221,8 @@
char *stpcpy(char *dest, const char *src)
{
- size_t max_size, len;
+ uint max_size;
+ size_t len;
if (!real_memcpy)
real_memcpy = (memcpy_t) getLibraryFunction("memcpy");
@@ -251,7 +254,8 @@
#ifndef MISSING_WCSNLEN
wchar_t *wcscpy(wchar_t *dest, const wchar_t *src)
{
- size_t max_bytes, max_wchars, len;
+ size_t max_wchars, len;
+ uint max_bytes;
if (!real_wcscpy)
real_wcscpy = (wcscpy_t) getLibraryFunction("wcscpy");
@@ -291,7 +295,8 @@
wchar_t *wcpcpy(wchar_t *dest, const wchar_t *src)
{
- size_t max_bytes, max_wchars, len;
+ size_t max_wchars, len;
+ uint max_bytes;
if (!real_wcpcpy)
real_wcpcpy = (wcpcpy_t) getLibraryFunction("wcpcpy");
@@ -333,9 +338,15 @@
/*
* This is needed! See the strcpy() for the reason. -ab.
*/
-void *memcpy(void *dest, const void *src, size_t n)
+void *memcpy(void *dest, const void *src, size_t hack)
{
- size_t max_size;
+ /*
+ * a size_t IS an unsigned long everywhere, though it sometimes
+ * doesn't state so, making printf misinterpret it.
+ */
+ unsigned long n = hack;
+ uint max_size;
+
if (!real_memcpy)
real_memcpy = (memcpy_t) getLibraryFunction("memcpy");
@@ -344,11 +355,11 @@
return real_memcpy(dest, src, n);
if ((max_size = _libsafe_stackVariableP(dest)) == 0) {
- LOG(5, "memcpy(<heap var> , <src>, %d)\n", n);
+ LOG(5, "memcpy(<heap var> , <src>, %ld)\n", n);
return real_memcpy(dest, src, n);
}
- LOG(4, "memcpy(<stack var> , <src>, %d) stack limit=%d)\n", n, max_size);
+ LOG(4, "memcpy(<stack var> , <src>, %ld) stack limit=%d)\n", n, max_size);
if (n > max_size)
_libsafe_die("Overflow caused by memcpy()");
return real_memcpy(dest, src, n);
@@ -357,7 +368,7 @@
char *strcat(char *dest, const char *src)
{
- size_t max_size;
+ uint max_size;
uint dest_len, src_len;
if (!real_memcpy)
@@ -388,7 +399,7 @@
char *strncat(char *dest, const char *src, size_t n)
{
- size_t max_size;
+ uint max_size;
uint dest_len, src_len;
if (!real_strncat)
@@ -1008,12 +1019,31 @@
if (is_printf_convspec[(int)*p]) {
caddr_t addr;
c++;
+#if 0
+ /*
+ * cannot add va_list (ap here) with a number on alpha.
+ * this is faster than the other method, and might be
+ * a good idea to enable this on !alpha arch.
+ */
if (pnum) {
addr = *((caddr_t*)(ap + (atoi(pnum)-1)*sizeof(char*)));
}
else {
addr = *((caddr_t*)(ap + c*sizeof(char*)));
}
+#else
+ {
+ va_list apc;
+ uint nb = c + 1;
+
+ va_copy(apc, ap);
+ if (pnum)
+ nb = atoi(pnum);
+ addr = NULL;
+ while (nb--)
+ addr = va_arg(apc, caddr_t);
+ }
+#endif
if (*p == 'n') {
if (_libsafe_raVariableP((void *)(addr))) {
_libsafe_die("printf(\"%%n\")");
@@ -1172,12 +1202,32 @@
if (is_printf_convspec[(int)*p]) {
caddr_t addr;
c++;
+#if 0
+ /*
+ * cannot add va_list (ap here) with a number on alpha.
+ * this is faster than the other method, and might be
+ * a good idea to enable this on !alpha arch.
+ */
+
if (pnum) {
addr = *((caddr_t*)(ap + (atoi(pnum)-1)*sizeof(char*)));
}
else {
addr = *((caddr_t*)(ap + c*sizeof(char*)));
}
+#else
+ {
+ va_list apc;
+ uint nb = c + 1;
+
+ va_copy(apc, ap);
+ if (pnum)
+ nb = atoi(pnum);
+ addr = NULL;
+ while (nb--)
+ addr = va_arg(apc, caddr_t);
+ }
+#endif
if (*p == 'n') {
if (_libsafe_raVariableP((void *)(addr))) {
_libsafe_die("printf(\"%%n\")");
@@ -1194,7 +1244,7 @@
int sprintf(char *str, const char *format, ...)
{
- size_t max_size;
+ uint max_size;
va_list ap;
int res;
@@ -1242,7 +1292,7 @@
int snprintf(char *str, size_t size, const char *format, ...)
{
- size_t max_size;
+ uint max_size;
va_list ap;
int res;
@@ -1288,7 +1338,7 @@
int vsprintf(char *str, const char *format, va_list ap)
{
- size_t max_size;
+ uint max_size;
int res;
if (!real_vsprintf)
@@ -1325,7 +1375,7 @@
int vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
- size_t max_size;
+ uint max_size;
int res;
if (!real_vsnprintf)
@@ -1360,7 +1410,7 @@
char *getwd(char *buf)
{
- size_t max_size;
+ uint max_size;
char *res;
if (!real_getwd)
@@ -1384,7 +1434,8 @@
char *gets(char *s)
{
- size_t max_size, len;
+ uint max_size;
+ size_t len;
if (!real_gets)
real_gets = (gets_t) getLibraryFunction("gets");
@@ -1409,7 +1460,8 @@
char *realpath(char *path, char resolved_path[])
{
- size_t max_size, len;
+ uint max_size;
+ size_t len;
char *res;
char buf[MAXPATHLEN + 1];