# HG changeset patch # User Sebastien Decugis # Date 1243477764 -32400 # Node ID 2bb3642696eca5bca060234723a86eaa9aeca292 # Parent 88e170a796277a41a9e6a908946cb991ed4f6c49 Added test for new sess_new flag and fixed segfault issue diff -r 88e170a79627 -r 2bb3642696ec waaad/session.c --- a/waaad/session.c Thu May 28 11:15:14 2009 +0900 +++ b/waaad/session.c Thu May 28 11:29:24 2009 +0900 @@ -431,9 +431,12 @@ { int len; char * secopt = NULL; + char * dupopt; /* so that we can modify the string in case it's a constant */ + + CHECK_MALLOC( dupopt = strdup(opt) ); /* Compute the size of the new string */ - len = strlen(opt); + len = strlen(dupopt); len += 2 * ( 1 /* ';' */ + 10 /* uint32_t max = 4294967295 = 10 digits */ ); len++; /* for the final '\0' in the worst case */ @@ -447,17 +450,20 @@ ++g_sid_l; /* Search a ';' in opt */ - secopt = strchr(opt, ';'); + secopt = strchr(dupopt, ';'); /* Now write the new value */ if (secopt) { - *secopt++ = '\0'; - strsz = snprintf(str, len, "%s;%u;%u;%s", opt, g_sid_h, g_sid_l, secopt); + *secopt = '\0'; + secopt++; + strsz = snprintf(str, len, "%s;%u;%u;%s", dupopt, g_sid_h, g_sid_l, secopt); } else { - strsz = snprintf(str, len, "%s;%u;%u", opt, g_sid_h, g_sid_l); + strsz = snprintf(str, len, "%s;%u;%u", dupopt, g_sid_h, g_sid_l); } CHECK_POSIX_DO( ret = pthread_mutex_unlock(&g_sid_lock), goto end ); + + free(dupopt); } break; diff -r 88e170a79627 -r 2bb3642696ec waaad/tests/testsess.c --- a/waaad/tests/testsess.c Thu May 28 11:15:14 2009 +0900 +++ b/waaad/tests/testsess.c Thu May 28 11:29:24 2009 +0900 @@ -91,7 +91,7 @@ CHECK( 0, sess_new ( &session2, SESSION_NEW_DEFAULT, "user@testsess" ) ); CHECK( 0, sess_getsid ( session2, &str) ); CHECK( 0, strcmp( ";user@testsess", str + strlen(str) - strlen(";user@testsess")) ); /* verify the end of the string */ - + /* Test the link and unlink */ CHECK( 0, sess_link ( session2 ) ); session = session2; @@ -101,6 +101,20 @@ CHECK( EINVAL, sess_unlink ( &session2 ) ); CHECK( 0, sess_new ( &session2, SESSION_NEW_DEFAULT, "user@testsess" ) ); + /* Create a session for other peer */ + #define ANOTHER_ID "another.diameter.id" + #define ANOTHER_OPT ";with@opt.str" + CHECK( 0, sess_new ( &session3, SESSION_NEW_OTHER, ANOTHER_ID ) ); + CHECK( 0, sess_getsid ( session3, &str) ); + CHECK( 0, strncmp( ANOTHER_ID, str, strlen(ANOTHER_ID)) ); /* verify the beginning of the string */ + CHECK( 0, sess_unlink ( &session3 ) ); + + CHECK( 0, sess_new ( &session3, SESSION_NEW_OTHER, ANOTHER_ID ANOTHER_OPT ) ); + CHECK( 0, sess_getsid ( session3, &str) ); + CHECK( 0, strncmp( ANOTHER_ID, str, strlen(ANOTHER_ID)) ); /* verify the beginning of the string */ + CHECK( 0, strcmp( ANOTHER_OPT, str + strlen(str) - strlen(ANOTHER_OPT)) ); /* verify the end of the string */ + CHECK( 0, sess_unlink ( &session3 ) ); + /* Create a third session */ CHECK( 0, sess_new ( &session3, SESSION_NEW_SEQUENCE, "1;1;another_test_session" ) );