Browse code

make sending ancillary data at wrong time a protocol error. change testcase accordingly.

git-svn: trunk@4805

Török Edvin authored on 2009/02/18 00:59:31
Showing 3 changed files
... ...
@@ -1,3 +1,9 @@
1
+Tue Feb 17 17:33:06 EET 2009 (edwin)
2
+------------------------------------
3
+ * clamd/server-th.c, unit_tests/check_clamd.c: make sending
4
+ ancillary data at wrong time a protocol error.  change testcase
5
+ accordingly.
6
+
1 7
 Tue Feb 17 17:11:17 EET 2009 (edwin)
2 8
 ------------------------------------
3 9
  * clamd/clamd.c, shared/optparser.c, shared/output.h: sendtimeout
... ...
@@ -989,6 +989,10 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
989 989
 		if (conn.scanfd != -1 && conn.scanfd != buf->dumpfd) {
990 990
 		    logg("*Unclaimed file descriptor received, closing: %d\n", conn.scanfd);
991 991
 		    close(conn.scanfd);
992
+		    /* protocol error */
993
+		    conn_reply_error(&conn, "PROTOCOL ERROR: ancillary data sent without FILDES.");
994
+		    error = 1;
995
+		    break;
992 996
 		}
993 997
 		buf->mode = conn.mode;
994 998
 		buf->id = conn.id;
... ...
@@ -479,25 +479,43 @@ END_TEST
479 479
 
480 480
 START_TEST (test_fildes_unwanted)
481 481
 {
482
+    char *recvdata;
483
+    size_t len;
484
+    int dummyfd;
485
+    conn_setup();
486
+    dummyfd = open(SCANFILE, O_RDONLY);
487
+
488
+    /* send a 'zVERSION\0' including the ancillary data.
489
+     * The \0 is from the extra char needed when sending ancillary data */
490
+    fail_unless_fmt(sendmsg_fd(sockd, "zIDSESSION", strlen("zIDSESSION"), dummyfd, 1) != -1,
491
+		    "sendmsg failed: %s\n", strerror(errno));
492
+
493
+    recvdata = recvfull(sockd, &len);
494
+
495
+    fail_unless_fmt(!strcmp(recvdata,"1: PROTOCOL ERROR: ancillary data sent without FILDES. ERROR"),
496
+		    "Wrong reply: %s\n", recvdata);
497
+
498
+    free(recvdata);
499
+    close(dummyfd);
500
+    conn_teardown();
501
+}
502
+END_TEST
503
+
504
+START_TEST (test_idsession_stress)
505
+{
482 506
     char buf[BUFSIZ];
483 507
     size_t i;
484
-    int dummyfd;
485 508
     char *data, *p;
486 509
     size_t len;
487 510
 
488 511
     conn_setup();
489
-    dummyfd = open(SCANFILE, O_RDONLY);
490 512
 
491 513
     fail_unless_fmt(send(sockd, "zIDSESSION", sizeof("zIDSESSION"), 0) == sizeof("zIDSESSION"),
492 514
 		    "send() failed: %s\n", strerror(errno));
493 515
     for (i=0;i < 1024; i++) {
494 516
 	snprintf(buf, sizeof(buf), "%u", i+1);
495
-	/* send a 'zVERSION\0' including the ancillary data.
496
-	 * The \0 is from the extra char needed when sending ancillary data */
497
-	fail_unless_fmt(sendmsg_fd(sockd, "zVERSION", sizeof("zVERSION")-1, dummyfd, 1) != -1,
498
-			"sendmsg (%u) failed: %s\n", i, strerror(errno));
499
-/*	fail_unless(send(sockd, "zVERSION", sizeof("zVERSION"), 0) == sizeof("zVERSION"),
500
-		    "send failed: %s\n",strerror(errno));*/
517
+	fail_unless(send(sockd, "zVERSION", sizeof("zVERSION"), 0) == sizeof("zVERSION"),
518
+		    "send failed: %s\n",strerror(errno));
501 519
 	data = recvpartial(sockd, &len, 1);
502 520
 	p = strchr(data, ':');
503 521
 	fail_unless_fmt(!!p, "wrong VERSION reply (%u): %s\n", i, data);
... ...
@@ -511,7 +529,6 @@ START_TEST (test_fildes_unwanted)
511 511
 	free(data);
512 512
     }
513 513
 
514
-    close(dummyfd);
515 514
     conn_teardown();
516 515
 }
517 516
 END_TEST
... ...
@@ -584,7 +601,6 @@ static Suite *test_clamd_suite(void)
584 584
 {
585 585
     Suite *s = suite_create("clamd");
586 586
     TCase *tc_commands, *tc_stress;
587
-
588 587
     tc_commands = tcase_create("clamd commands");
589 588
     suite_add_tcase(s, tc_commands);
590 589
     tcase_add_unchecked_fixture(tc_commands, commands_setup, commands_teardown);
... ...
@@ -593,12 +609,12 @@ static Suite *test_clamd_suite(void)
593 593
     tcase_add_loop_test(tc_commands, test_fildes, 0, 4*sizeof(fildes_cmds)/sizeof(fildes_cmds[0]));
594 594
     tcase_add_test(tc_commands, test_stats);
595 595
     tcase_add_test(tc_commands, test_instream);
596
-
597 596
     tc_stress = tcase_create("clamd stress test");
598 597
     suite_add_tcase(s, tc_stress);
599 598
     tcase_add_test(tc_stress, test_fildes_many);
600
-    tcase_add_test(tc_stress, test_fildes_unwanted);
599
+    tcase_add_test(tc_stress, test_idsession_stress);
601 600
     tcase_add_test(tc_stress, test_connections);
601
+    tcase_add_test(tc_stress, test_fildes_unwanted);
602 602
 
603 603
     return s;
604 604
 }