r17724: don't rely on strnlen() as MacOSX 10.4 doesn't have it. Someday apple
authorAndrew Tridgell <tridge@samba.org>
Tue, 22 Aug 2006 23:12:22 +0000 (23:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:16:32 +0000 (14:16 -0500)
will realise that buffer overflows are bad ....
(This used to be commit 0a6968b71b3cc492edfc3d46bd7e0c66c7ed8557)

source4/lib/ldb/ldb_tdb/ldb_pack.c

index c6edf663ae18719aa43bdc7b807db949b099ff34..b2a004b99f2b68d00d0acaffb4499fbbf61082cf 100644 (file)
@@ -155,6 +155,16 @@ int ltdb_pack_data(struct ldb_module *module,
        return 0;
 }
 
+/* using this means we can compile standalone on broken systems like
+   MacOSX 10.4 */
+static size_t ldb_strnlen(const char *s, size_t n)
+{
+       int i;
+       for (i=0; s[i] && i<n; i++)
+               /* noop */ ;
+       return i;
+}
+
 /*
   unpack a ldb message from a linear buffer in TDB_DATA
 
@@ -191,7 +201,7 @@ int ltdb_unpack_data(struct ldb_module *module,
                break;
 
        case LTDB_PACKING_FORMAT:
-               len = strnlen((char *)p, remaining);
+               len = ldb_strnlen((char *)p, remaining);
                if (len == remaining) {
                        errno = EIO;
                        goto failed;
@@ -234,7 +244,7 @@ int ltdb_unpack_data(struct ldb_module *module,
                        errno = EIO;
                        goto failed;
                }
-               len = strnlen((char *)p, remaining-6);
+               len = ldb_strnlen((char *)p, remaining-6);
                if (len == remaining-6) {
                        errno = EIO;
                        goto failed;