Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests/test_myldap.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2010-05-07 22:43:23 +0200
committerArthur de Jong <arthur@arthurdejong.org>2010-05-07 22:43:23 +0200
commitc35d25bb095330e6c5f2510cffbab9170675af32 (patch)
tree1ac2441ff94dffd03045d9e1d019f50f05846a53 /tests/test_myldap.c
parent6941b4e0674c313d1471c0331cc50712a784d458 (diff)
implement test for buffer overflow
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1086 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'tests/test_myldap.c')
-rw-r--r--tests/test_myldap.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_myldap.c b/tests/test_myldap.c
index ff2f27e..589138f 100644
--- a/tests/test_myldap.c
+++ b/tests/test_myldap.c
@@ -33,6 +33,26 @@
#include "nslcd/cfg.h"
#include "nslcd/myldap.h"
+#ifndef __ASSERT_FUNCTION
+#define __ASSERT_FUNCTION ""
+#endif /* not __ASSERT_FUNCTION */
+
+#define assertstreq(str1,str2) \
+ (assertstreq_impl(str1,str2,"strcmp(" __STRING(str1) "," __STRING(str2) ")==0", \
+ __FILE__, __LINE__, __ASSERT_FUNCTION))
+
+/* for Solaris: */
+#define __assert_fail(assertion,file,line,function) __assert(assertion,file,line)
+
+/* method for determening string equalness */
+static void assertstreq_impl(const char *str1,const char *str2,
+ const char *assertion,const char *file,
+ int line,const char *function)
+{
+ if (strcmp(str1,str2)!=0)
+ __assert_fail(assertion,file,line,function);
+}
+
struct worker_args {
int id;
};
@@ -394,6 +414,16 @@ static void test_connections(void)
nslcd_cfg->ldc_uris[i].uri=old_uris[i];
}
+/* test whether myldap_escape() handles buffer overlows correctly */
+static void test_escape(void)
+{
+ char buffer[1024];
+ assert(myldap_escape("test",buffer,4)!=0);
+ assert(myldap_escape("t*st",buffer,5)!=0);
+ assert(myldap_escape("t*st",buffer,20)==0);
+ assertstreq(buffer,"t\\2ast");
+}
+
/* the main program... */
int main(int argc,char *argv[])
{
@@ -424,5 +454,6 @@ int main(int argc,char *argv[])
test_two_searches();
test_threads();
test_connections();
+ test_escape();
return 0;
}