@@ -12,14 +12,12 @@ static void test_basic_state(void)
1212{
1313 int fds [2 ];
1414 char buf [16 ];
15- char custom [32 ];
1615 auplugin_fgets_state_t * st ;
1716
1817 assert (pipe (fds ) == 0 );
1918
2019 st = auplugin_fgets_init ();
2120 assert (st );
22- assert (auplugin_setvbuf_r (st , custom , sizeof (custom ), MEM_SELF_MANAGED ) == 0 );
2321
2422 /* no data yet */
2523 assert (auplugin_fgets_more_r (st , sizeof (buf )) == 0 );
@@ -48,29 +46,31 @@ static void test_deferred_compaction(void)
4846{
4947 int fds [2 ];
5048 char buf [64 ];
51- char custom [ 33 ] ;
49+ char * custom ;
5250 const char * line =
5351 "0123456789abcdef0123456789abcdefQRSTUVWX\n" ;
5452 auplugin_fgets_state_t * st ;
5553 size_t line_len = strlen (line );
56- size_t capacity = sizeof ( custom ) - 1 ;
54+ size_t capacity = 33 ;
5755
5856 assert (pipe (fds ) == 0 );
5957 st = auplugin_fgets_init ();
6058 assert (st );
61- assert (auplugin_setvbuf_r (st , custom , capacity , MEM_SELF_MANAGED ) == 0 );
59+ custom = malloc (capacity );
60+ assert (custom );
61+ assert (auplugin_setvbuf_r (st , custom , capacity , MEM_MALLOC ) == 0 );
6262
6363 assert (write (fds [1 ], line , line_len ) == (ssize_t )line_len );
6464 close (fds [1 ]);
6565
6666 int len = auplugin_fgets_r (st , buf , sizeof (buf ), fds [0 ]);
67- assert (len == (int )capacity );
67+ assert (len == (int )( capacity - 1 ) );
6868 assert (strncmp (buf , line , (size_t )len ) == 0 );
6969 assert (auplugin_fgets_eof_r (st ) == 0 );
7070
7171 len = auplugin_fgets_r (st , buf , sizeof (buf ), fds [0 ]);
72- assert (len == (int )(line_len - capacity ));
73- assert (strcmp (buf , line + capacity ) == 0 );
72+ assert (len == (int )(line_len - ( capacity - 1 ) ));
73+ assert (strcmp (buf , line + ( capacity - 1 ) ) == 0 );
7474
7575 len = auplugin_fgets_r (st , buf , sizeof (buf ), fds [0 ]);
7676 assert (len == 0 );
@@ -80,6 +80,17 @@ static void test_deferred_compaction(void)
8080 auplugin_fgets_destroy (st );
8181}
8282
83+ static void test_reject_self_managed_override (void )
84+ {
85+ auplugin_fgets_state_t * st ;
86+ char custom [32 ];
87+
88+ st = auplugin_fgets_init ();
89+ assert (st );
90+ assert (auplugin_setvbuf_r (st , custom , sizeof (custom ), MEM_SELF_MANAGED ) == 1 );
91+ auplugin_fgets_destroy (st );
92+ }
93+
8394static void test_mmap_file (void )
8495{
8596 const char * srcdir = getenv ("srcdir" ) ? getenv ("srcdir" ) : "." ;
@@ -122,8 +133,8 @@ int main(void)
122133{
123134 test_basic_state ();
124135 test_deferred_compaction ();
136+ test_reject_self_managed_override ();
125137 test_mmap_file ();
126138 printf ("audit-fgets_r tests: all passed\n" );
127139 return 0 ;
128140}
129-
0 commit comments