Our current tests do not invoke hstor_keys at all, and so they did not catch
a crash with double free in append_qparam.

Add a very basic test which at least calls hstor_keys to verify that it
does not crash right away. This test does not excercise complex modes
such as S3 paging, but better this than nothing.

Signed-off-by: Pete Zaitcev <zait...@redhat.com>

---
 test/Makefile.am |    4 +
 test/list-keys.c |  102 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 1 deletion(-)

PASS: hdr-meta
tabled[6562]: client ::ffff:127.0.0.1 connected
chunkd[6560]: client host ::ffff:127.0.0.1 port 44394 connected
chunkd[6560]: client host ::ffff:127.0.0.1 port 44394 disconnected
*** glibc detected *** ./list-keys: double free or corruption (fasttop): 
0x0000000000e93dc0 ***
/bin/sh: line 5:  6609 Segmentation fault      (core dumped) top_srcdir=.. 
${dir}$tst
FAIL: list-keys

diff --git a/test/Makefile.am b/test/Makefile.am
index 9264cba..cc4e6fe 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -26,11 +26,12 @@ TESTS =                             \
        large-object            \
        hdr-content-type        \
        hdr-meta                \
+       list-keys               \
        stop-daemon             \
        clean-db
 
 check_PROGRAMS         = basic-bucket basic-object it-works large-object \
-                         hdr-content-type hdr-meta wait-for-listen
+                         hdr-content-type hdr-meta list-keys wait-for-listen
 
 noinst_LIBRARIES       = libtest.a
 
@@ -43,6 +44,7 @@ large_object_LDADD    = $(TESTLDADD)
 hdr_content_type_LDADD = $(TESTLDADD)
 hdr_meta_LDADD         = $(TESTLDADD)
 it_works_LDADD         = $(TESTLDADD)
+list_keys_LDADD                = $(TESTLDADD)
 
 wait_for_listen_LDADD  = libtest.a
 
diff --git a/test/list-keys.c b/test/list-keys.c
new file mode 100644
index 0000000..8126e0a
--- /dev/null
+++ b/test/list-keys.c
@@ -0,0 +1,102 @@
+
+/*
+ * Copyright 2008-2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#define _GNU_SOURCE
+#include "tabled-config.h"
+
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+// #include <ctype.h>
+#include <locale.h>
+#include <glib.h>
+#include <hstor.h>
+#include "test.h"
+
+static char bucket[] = "test-hdr-meta";
+static char key[] = "test-key";
+static char value[] = "test-value";
+
+static void runtest(struct hstor_client *hstor)
+{
+       struct hstor_keylist *keylist;
+       struct hstor_object *obj;
+       GList *tmp;
+       int cnt;
+
+       keylist = hstor_keys(hstor, bucket, "", NULL, "/", 20);
+       OK(keylist);
+
+       cnt = 0;
+       tmp = keylist->contents;
+       while (tmp) {
+               obj = tmp->data;
+               if (strcmp(obj->key, key) != 0) {
+                       fprintf(stderr, "bad object key %s\n", obj->key);
+                       exit(1);
+               }
+               if (obj->size != sizeof(value)) {
+                       fprintf(stderr, "bad object size %ld\n",
+                               (long)obj->size);
+                       exit(1);
+               }
+               cnt++;
+               tmp = tmp->next;
+       }
+       if (cnt != 1) {
+               fprintf(stderr, "bad object count %d\n", cnt);
+               exit(1);
+       }
+
+       hstor_free_keylist(keylist);
+}
+
+int main(int argc, char *argv[])
+{
+       struct hstor_client *hstor;
+       char accbuf[80];
+       int rc;
+       bool rcb;
+
+       setlocale(LC_ALL, "C");
+
+       rc = tb_readport(TEST_FILE_TB, accbuf, sizeof(accbuf));
+       OK(rc > 0);
+
+       hstor = hstor_new(accbuf, TEST_HOST, TEST_USER, TEST_USER_KEY);
+       OK(hstor);
+
+       /* add bucket - since tests are independent, we do not rely on others */
+       rcb = hstor_add_bucket(hstor, bucket);
+       OK(rcb);
+
+       rcb = hstor_put_inline(hstor, bucket, key, value, sizeof(value), NULL);
+       OK(rcb);
+
+       runtest(hstor);
+
+       rcb = hstor_del(hstor, bucket, key);
+       OK(rcb);
+
+       rcb = hstor_del_bucket(hstor, bucket);
+       OK(rcb);
+
+       return 0;
+}
+
--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to