Fix: Read from pointer after free in unit tests
authorDavid Goulet <dgoulet@efficios.com>
Tue, 14 May 2013 17:22:27 +0000 (13:22 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 15 May 2013 14:21:07 +0000 (10:21 -0400)
Issue 1019886 and 1019887 of coverity scan.

Signed-off-by: David Goulet <dgoulet@efficios.com>
tests/unit/test_session.c

index 8e1da214806d105975bc5853270a68444246da03..7242edded9879640cddfd2f408168ecf4b87397b 100644 (file)
@@ -151,15 +151,14 @@ static int create_one_session(char *name)
 static int destroy_one_session(struct ltt_session *session)
 {
        int ret;
+       char session_name[NAME_MAX];
 
-       ret = session_destroy(session);
+       strncpy(session_name, session->name, sizeof(session->name));
+       session_name[sizeof(session_name) - 1] = '\0';
 
+       ret = session_destroy(session);
        if (ret == LTTNG_OK) {
-               /* Validate */
-               if (session == NULL) {
-                       return 0;
-               }
-               ret = find_session_name(session->name);
+               ret = find_session_name(session_name);
                if (ret < 0) {
                        /* Success, -1 means that the sesion is NOT found */
                        return 0;
@@ -280,7 +279,7 @@ void test_large_session_number(void)
                cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) {
                        ret = destroy_one_session(iter);
                        if (ret < 0) {
-                               diag("session %d (name: %s) destroy failed", i, iter->name);
+                               diag("session %d destroy failed", i);
                                ++failed;
                        }
                }
This page took 0.026052 seconds and 4 git commands to generate.