[uClibc] libsafe does not build against uClibc
Peter S. Mazinger
ps.m at gmx.net
Tue Oct 12 16:09:26 UTC 2004
On Tue, 5 Oct 2004, Erik Andersen wrote:
> On Tue Oct 05, 2004 at 10:45:24AM +0200, Peter S. Mazinger wrote:
> > Hello!
> >
> > Trying to build libsafe it misses _IO_vfscanf? Has someone managed to
> > build it against uClibc?
> > Would it be correct to replace _IO_vfscanf w/ vfscanf?
>
> _IO_vfscanf is a glibc internal function. _IO_vfscanf and
> vfscanf implement the same function but have different function
> prototypes:
>
> int _IO_vfscanf (_IO_FILE *s, const char *format, _IO_va_list argptr, int *errp)
> int vfscanf (FILE *s, const char *format, va_list argptr)
>
> Whatever libsafe is doing (presumably replaceing vfscanf to check
> for buffer overflows), it is clearly being extra friendly with
> glibc,
Attached a patch for libsafe to be used w/ uClibc.
Peter
--
Peter S. Mazinger <ps dot m at gmx dot net> ID: 0xA5F059F2
Key fingerprint = 92A4 31E1 56BC 3D5A 2D08 BB6E C389 975E A5F0 59F2
____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most! http://www.freestart.hu
-------------- next part --------------
--- src/intercept.c.orig 2004-10-05 16:15:31.000000000 +0200
+++ src/intercept.c 2004-10-05 16:44:13.000000000 +0200
@@ -44,11 +44,17 @@
#include <stdarg.h> /* defines va_args */
#define __NO_STRING_INLINES 1 /* stops the inline expansion of strcpy() */
#define __USE_GNU 1 /* defines strnlen() */
+/* disable getwd on uClibc */
+#ifdef __UCLIBC__
+#undef __USE_BSD
+#endif
#include <string.h> /* defines strncat() */
#include <unistd.h> /* defines getcwd(), readlink() */
#include <sys/param.h> /* MAXPATHLEN for realpath() */
+#if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED)
#include <limits.h> /* PATH_MAX for getwd(); actually in */
/* linux/limits.h */
+#endif
#include <pwd.h> /* defines getpass() */
#include <errno.h> /* defines errno */
#include <dlfcn.h> /* defines dlsym() */
@@ -75,11 +81,17 @@
ap);
typedef int (*vprintf_t) (const char *format, va_list ap);
typedef int (*vfprintf_t) (FILE *fp, const char *format, va_list ap);
+#if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED)
typedef char *(*getwd_t) (char *buf);
+#endif
typedef char *(*gets_t) (char *s);
typedef char *(*realpath_t) (char *path, char resolved_path[]);
+#ifndef __UCLIBC__
typedef int (*_IO_vfscanf_t) (_IO_FILE *s, const char *format, _IO_va_list
argptr, int *errp);
+#else
+typedef int (*vfscanf_t) (FILE *s, const char *format, va_list argptr);
+#endif
@@ -134,12 +146,18 @@
* segfault.
*/
static memcpy_t real_memcpy = NULL;
+#ifndef __UCLIBC__
static _IO_vfscanf_t real_IO_vfscanf = NULL;
+#else
+static vfscanf_t real_vfscanf = NULL;
+#endif
static vfprintf_t real_vfprintf = NULL;
static vsnprintf_t real_vsnprintf = NULL;
static vsprintf_t real_vsprintf = NULL;
static gets_t real_gets = NULL;
+#if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED)
static getwd_t real_getwd = NULL;
+#endif
static realpath_t real_realpath = NULL;
static stpcpy_t real_stpcpy = NULL;
static strcat_t real_strcat = NULL;
@@ -1358,6 +1376,7 @@
}
+#if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED)
char *getwd(char *buf)
{
size_t max_size;
@@ -1380,6 +1399,7 @@
_libsafe_die("Overflow caused by getwd()");
return res;
}
+#endif
char *gets(char *s)
@@ -1439,21 +1459,38 @@
}
+#ifndef __UCLIBC__
int _IO_vfscanf (_IO_FILE *s, const char *format, _IO_va_list argptr, int *errp)
+#else
+int vfscanf (FILE *s, const char *format, va_list argptr)
+#endif
{
int res, save_count;
caddr_t ra_array[MAXLEVELS], fp_array[MAXLEVELS];
+#ifndef __UCLIBC__
if (!real_IO_vfscanf)
real_IO_vfscanf = (_IO_vfscanf_t) getLibraryFunction("_IO_vfscanf");
+#else
+ if (!real_vfscanf)
+ real_vfscanf = (vfscanf_t) getLibraryFunction("vfscanf");
+#endif
if (_libsafe_exclude)
+#ifndef __UCLIBC__
return real_IO_vfscanf(s, format, argptr, errp);
+#else
+ return real_vfscanf(s, format, argptr);
+#endif
save_count = _libsafe_save_ra_fp(sizeof(ra_array)/sizeof(caddr_t),
ra_array, fp_array);
+#ifndef __UCLIBC__
res = real_IO_vfscanf(s, format, argptr, errp);
+#else
+ res = real_vfscanf(s, format, argptr);
+#endif
if (save_count >= 0 && _libsafe_verify_ra_fp(save_count, ra_array,
fp_array) == -1)
@@ -1473,7 +1510,9 @@
static void _intercept_init() __attribute__ ((constructor));
static void _intercept_fini() __attribute__ ((destructor));
-
+#if !defined(__USE_BSD) && !defined(__USE_XOPEN_EXTENDED)
+extern int readlink (const char *path, char *buf, size_t len);
+#endif
static char *get_exename(char *exename, int size) {
int res;
@@ -1526,12 +1565,18 @@
}
real_memcpy = (memcpy_t) getLibraryFunction("memcpy");
+#ifndef __UCLIBC__
real_IO_vfscanf = (_IO_vfscanf_t) getLibraryFunction("_IO_vfscanf");
+#else
+ real_vfscanf = (vfscanf_t) getLibraryFunction("vfscanf");
+#endif
real_vfprintf = (vfprintf_t) getLibraryFunction("vfprintf");
real_vsnprintf = (vsnprintf_t) getLibraryFunction("vsnprintf");
real_vsprintf = (vsprintf_t) getLibraryFunction("vsprintf");
real_gets = (gets_t) getLibraryFunction("gets");
+#if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED)
real_getwd = (getwd_t) getLibraryFunction("getwd");
+#endif
real_realpath = (realpath_t) getLibraryFunction("realpath");
real_stpcpy = (stpcpy_t) getLibraryFunction("stpcpy");
real_strcat = (strcat_t) getLibraryFunction("strcat");
--- src/util.h.orig 2004-10-05 16:28:59.000000000 +0200
+++ src/util.h 2004-10-05 16:42:38.000000000 +0200
@@ -47,6 +47,9 @@
extern uint _libsafe_span_stack_frames(void *start_addr, void *end_addr);
extern void _libsafe_die(char *format, ...);
extern void _libsafe_warn(char *format, ...);
+#ifndef __USE_BSD
+typedef __caddr_t caddr_t;
+#endif
extern int _libsafe_save_ra_fp(int maxcount, caddr_t *ra_array, caddr_t
*fp_array);
extern int _libsafe_verify_ra_fp(int maxcount, caddr_t *ra_array, caddr_t
More information about the uClibc
mailing list