sec-2853.c revision 290000
1#include <config.h> 2 3#include <rc_cmdlength.h> 4 5#include "unity.h" 6 7void setUp(void); 8void tearDown(void); 9 10void test_main( void ); 11int basic_good( void ); 12int embedded_nul( void ); 13int trailing_space( void ); 14 15static int verbose = 1; // if not 0, also print results if test passed 16static int exit_on_err = 0; // if not 0, exit if test failed 17 18 19void setUp(void) 20{ 21} 22 23 24void tearDown(void) 25{ 26} 27 28 29/* 30 * Test function calling the remote config buffer checker 31 * http://bugs.ntp.org/show_bug.cgi?id=2853 32 * 33 * size_t remoteconfig_cmdlength(const char *src_buf, const char *src_end) 34 * - trims whitespace & garbage from the right 35 * then looks for only \tSP-\127 starting from the left. 36 * It returns the number of "good" characters it found. 37 */ 38 39 40void test_main( void ) 41{ 42 TEST_ASSERT_EQUAL(0, basic_good()); 43 TEST_ASSERT_EQUAL(0, embedded_nul()); 44 TEST_ASSERT_EQUAL(0, trailing_space()); 45} 46 47 48int basic_good( void ) 49{ 50 const char string[] = "good"; 51 const char *EOstring; 52 char *cp; 53 size_t len; 54 int failed; 55 56 EOstring = string + sizeof string; 57 58 len = remoteconfig_cmdlength(string, EOstring); 59 60 failed = ( 4 != len ); 61 62 if ( failed || verbose ) 63 printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n", 64 string, 65 len, 66 4, 67 failed ? "NO <<" : "yes" ); 68 69 return failed ? -1 : 0; 70} 71 72 73int embedded_nul( void ) 74{ 75 const char string[] = "nul\0 there"; 76 const char *EOstring; 77 char *cp; 78 size_t len; 79 int failed; 80 81 EOstring = string + sizeof string; 82 83 len = remoteconfig_cmdlength(string, EOstring); 84 85 failed = ( 3 != len ); 86 87 if ( failed || verbose ) 88 printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n", 89 string, 90 len, 91 3, 92 failed ? "NO <<" : "yes" ); 93 94 return failed ? -1 : 0; 95} 96 97 98int trailing_space( void ) 99{ 100 const char string[] = "trailing space "; 101 const char *EOstring; 102 char *cp; 103 size_t len; 104 int failed; 105 106 EOstring = string + sizeof string; 107 108 len = remoteconfig_cmdlength(string, EOstring); 109 110 failed = ( 14 != len ); 111 112 if ( failed || verbose ) 113 printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n", 114 string, 115 len, 116 14, 117 failed ? "NO <<" : "yes" ); 118 119 return failed ? -1 : 0; 120} 121