]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Sec 2853] Initial work on tests/sec-2853/. Harlan Stenn.
authorHarlan Stenn <stenn@ntp.org>
Thu, 25 Jun 2015 02:43:46 +0000 (02:43 +0000)
committerHarlan Stenn <stenn@ntp.org>
Thu, 25 Jun 2015 02:43:46 +0000 (02:43 +0000)
bk: 558b6ae2kaVYI0sE7HfKAWLlgOJY8Q

tests/sec-2853/sec-2853.c

index a90b42cf9610cf591523ddb0263fad306e6acf15..c0e0a0ee004805153f1cf2e2dad91ff7d72518ec 100644 (file)
@@ -1,6 +1,6 @@
 #include <config.h>
 
-#include <ntp_fp.h>
+//#include <ntp_fp.h>
 
 #include "unity.h"
 
@@ -9,6 +9,9 @@ void tearDown(void);
 
 void test_main( void );
 int basic_good( void );
+int embedded_nul( void );
+int trailing_space( void );
+
 extern size_t remoteconfig_cmdlength(const char *, const char *);
 
 static int verbose = 1;        // if not 0, also print results if test passed
@@ -39,6 +42,8 @@ void tearDown(void)
 void test_main( void )
 {
        TEST_ASSERT_EQUAL(0, basic_good());
+       TEST_ASSERT_EQUAL(0, embedded_nul());
+       TEST_ASSERT_EQUAL(0, trailing_space());
 }
 
 
@@ -55,7 +60,7 @@ int basic_good( void )
 
        len = remoteconfig_cmdlength(string, EOstring);
 
-       failed = 4 != len;
+       failed = ( 4 != len );
 
        if ( failed || verbose )
                printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
@@ -66,3 +71,54 @@ int basic_good( void )
 
        return failed ? -1 : 0;
 }
+
+
+int embedded_nul( void )
+{
+       const char string[] = "nul\0 there";
+       const char *EOstring;
+       char *cp;
+       size_t len;
+       int failed;
+
+       EOstring = string + sizeof string;
+
+       len = remoteconfig_cmdlength(string, EOstring);
+
+       failed = ( 3 != len );
+
+       if ( failed || verbose )
+               printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
+                       string,
+                       len,
+                       3,
+                       failed ? "NO <<" : "yes" );
+
+       return failed ? -1 : 0;
+}
+
+
+int trailing_space( void )
+{
+       const char *string = "trailing space ";
+       const char *EOstring;
+       char *cp;
+       size_t len;
+       int failed;
+
+       EOstring = string;
+       for (cp = string; *cp++; ++EOstring) ;
+
+       len = remoteconfig_cmdlength(string, EOstring);
+
+       failed = ( 14 != len );
+
+       if ( failed || verbose )
+               printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
+                       string,
+                       len,
+                       14,
+                       failed ? "NO <<" : "yes" );
+
+       return failed ? -1 : 0;
+}