When building on Fedora 17 (which uses gcc 4.7.0) with -O0 in CFLAGS, three of the tests failed to compile. cputest.c and qemuxml2argvtest.c had non-static structs defined inside the macro that was being repeatedly invoked. Due to some so-far unidentified change in gcc, the stack space used by variables defined inside { } is not recovered/re-used when the block ends, so all these structs have become additive (this is the same problem worked around in commit cf57d345b). Fortunately, these two files could be fixed with a single line addition of "static" to the struct definition in the macro. virnettlscontexttest.c was a bit different, though. The structs were all defined inline as static already, but for some reason now take up space on the stack. The only reasonable solution here was to move all of the struct definitions outside of the function. In an ideal world, none of these changes should be necessary, but not knowing how long it will be until the gcc regressions are fixed, and since the code is just as correct after this patch as before, it makes sense to fix libvirt's build for -O0 while also reporting the gcc problem. --- tests/cputest.c | 2 +- tests/qemuxml2argvtest.c | 2 +- tests/virnettlscontexttest.c | 168 ++++++++++++++++++++++-------------------- 3 files changed, 91 insertions(+), 81 deletions(-) diff --git a/tests/cputest.c b/tests/cputest.c index 9928e5d..01db8f1 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -512,7 +512,7 @@ mymain(void) #define DO_TEST(arch, api, name, host, cpu, \ models, nmodels, preferred, result) \ do { \ - struct data data = { \ + static struct data data = { \ arch, api, host, cpu, models, \ models == NULL ? NULL : #models, \ nmodels, preferred, result \ diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 637ca50..fdbe95a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -314,7 +314,7 @@ mymain(void) # define DO_TEST_FULL(name, migrateFrom, migrateFd, \ expectError, expectFailure, ...) \ do { \ - struct testInfo info = { \ + static struct testInfo info = { \ name, NULL, migrateFrom, migrateFd, \ expectError, expectFailure \ }; \ diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c index 8e805d8..b4d1e0e 100644 --- a/tests/virnettlscontexttest.c +++ b/tests/virnettlscontexttest.c @@ -734,21 +734,6 @@ cleanup: return ret; } - -static int -mymain(void) -{ - int ret = 0; - if (asn1_array2tree(pkix_asn1_tab, &pkix_asn1, NULL) != ASN1_SUCCESS) - abort(); - - gnutls_global_init(); - - privkey = testTLSLoadKey(); - - if (virFileWriteStr(keyfile, PRIVATE_KEY, 0600) < 0) - return EXIT_FAILURE; - # define DO_CTX_TEST(isServer, caReq, certReq, expectFail) \ do { \ struct testTLSContextData data = { \ @@ -806,11 +791,6 @@ mymain(void) 0, 0, }; - - DO_CTX_TEST(true, cacertreq, servercertreq, false); - DO_CTX_TEST(false, cacertreq, clientcertreq, false); - - /* Some other CAs which are good */ /* Basic:CA:critical */ @@ -864,14 +844,6 @@ mymain(void) 0, 0, }; - DO_CTX_TEST(true, cacert1req, servercertreq, false); - DO_CTX_TEST(true, cacert2req, servercertreq, false); -# if 0 - DO_CTX_TEST(true, cacert3req, servercertreq, false); -# endif - DO_CTX_TEST(true, cacert4req, servercertreq, false); - DO_CTX_TEST(true, cacert5req, servercertreq, false); - /* Now some bad certs */ /* no-basic */ @@ -893,10 +865,6 @@ mymain(void) 0, 0, }; - DO_CTX_TEST(true, cacert6req, servercertreq, true); - DO_CTX_TEST(true, cacert7req, servercertreq, true); - - /* Various good servers */ /* no usage or purpose */ static struct testTLSCertReq servercert1req = { @@ -962,13 +930,6 @@ mymain(void) 0, 0, }; - DO_CTX_TEST(true, cacertreq, servercert1req, false); - DO_CTX_TEST(true, cacertreq, servercert2req, false); - DO_CTX_TEST(true, cacertreq, servercert3req, false); - DO_CTX_TEST(true, cacertreq, servercert4req, false); - DO_CTX_TEST(true, cacertreq, servercert5req, false); - DO_CTX_TEST(true, cacertreq, servercert6req, false); - DO_CTX_TEST(true, cacertreq, servercert7req, false); /* Bad servers */ /* usage:cert-sign:critical */ @@ -999,12 +960,6 @@ mymain(void) 0, 0, }; - DO_CTX_TEST(true, cacertreq, servercert8req, true); - DO_CTX_TEST(true, cacertreq, servercert9req, true); - DO_CTX_TEST(true, cacertreq, servercert10req, true); - - - /* Various good clients */ /* no usage or purpose */ static struct testTLSCertReq clientcert1req = { @@ -1070,13 +1025,6 @@ mymain(void) 0, 0, }; - DO_CTX_TEST(false, cacertreq, clientcert1req, false); - DO_CTX_TEST(false, cacertreq, clientcert2req, false); - DO_CTX_TEST(false, cacertreq, clientcert3req, false); - DO_CTX_TEST(false, cacertreq, clientcert4req, false); - DO_CTX_TEST(false, cacertreq, clientcert5req, false); - DO_CTX_TEST(false, cacertreq, clientcert6req, false); - DO_CTX_TEST(false, cacertreq, clientcert7req, false); /* Bad clients */ /* usage:cert-sign:critical */ @@ -1107,12 +1055,6 @@ mymain(void) 0, 0, }; - DO_CTX_TEST(false, cacertreq, clientcert8req, true); - DO_CTX_TEST(false, cacertreq, clientcert9req, true); - DO_CTX_TEST(false, cacertreq, clientcert10req, true); - - - /* Expired stuff */ static struct testTLSCertReq cacertexpreq = { @@ -1140,11 +1082,6 @@ mymain(void) 0, -1, }; - DO_CTX_TEST(true, cacertexpreq, servercertreq, true); - DO_CTX_TEST(true, cacertreq, servercertexpreq, true); - DO_CTX_TEST(false, cacertreq, clientcertexpreq, true); - - /* Not activated stuff */ static struct testTLSCertReq cacertnewreq = { @@ -1172,14 +1109,6 @@ mymain(void) 1, 2, }; - DO_CTX_TEST(true, cacertnewreq, servercertreq, true); - DO_CTX_TEST(true, cacertreq, servercertnewreq, true); - DO_CTX_TEST(false, cacertreq, clientcertnewreq, true); - - - DO_SESS_TEST(cacertreq, servercertreq, clientcertreq, false, false, "libvirt.org", NULL); - DO_SESS_TEST_EXT(cacertreq, cacert1req, servercertreq, clientcertreq, true, true, "libvirt.org", NULL); - /* When an altname is set, the CN is ignored, so it must be duplicated * as an altname for it to match */ static struct testTLSCertReq servercertalt1req = { @@ -1190,6 +1119,7 @@ mymain(void) true, true, GNUTLS_KP_TLS_WWW_SERVER, NULL, 0, 0, }; + /* This intentionally doesn't replicate */ static struct testTLSCertReq servercertalt2req = { NULL, NULL, "servercert.pem", "UK", @@ -1200,14 +1130,6 @@ mymain(void) 0, 0, }; - DO_SESS_TEST(cacertreq, servercertalt1req, clientcertreq, false, false, "libvirt.org", NULL); - DO_SESS_TEST(cacertreq, servercertalt1req, clientcertreq, false, false, "www.libvirt.org", NULL); - DO_SESS_TEST(cacertreq, servercertalt1req, clientcertreq, false, true, "wiki.libvirt.org", NULL); - - DO_SESS_TEST(cacertreq, servercertalt2req, clientcertreq, false, true, "libvirt.org", NULL); - DO_SESS_TEST(cacertreq, servercertalt2req, clientcertreq, false, false, "www.libvirt.org", NULL); - DO_SESS_TEST(cacertreq, servercertalt2req, clientcertreq, false, false, "wiki.libvirt.org", NULL); - const char *const wildcards1[] = { "C=UK,CN=dogfood", NULL, @@ -1234,6 +1156,94 @@ mymain(void) NULL, }; +static int +mymain(void) +{ + int ret = 0; + if (asn1_array2tree(pkix_asn1_tab, &pkix_asn1, NULL) != ASN1_SUCCESS) + abort(); + + gnutls_global_init(); + + privkey = testTLSLoadKey(); + + if (virFileWriteStr(keyfile, PRIVATE_KEY, 0600) < 0) + return EXIT_FAILURE; + + /* A perfect CA, perfect client & perfect server */ + DO_CTX_TEST(true, cacertreq, servercertreq, false); + DO_CTX_TEST(false, cacertreq, clientcertreq, false); + + + /* Some other CAs which are good */ + DO_CTX_TEST(true, cacert1req, servercertreq, false); + DO_CTX_TEST(true, cacert2req, servercertreq, false); +# if 0 + DO_CTX_TEST(true, cacert3req, servercertreq, false); +# endif + DO_CTX_TEST(true, cacert4req, servercertreq, false); + DO_CTX_TEST(true, cacert5req, servercertreq, false); + + /* Now some bad certs */ + DO_CTX_TEST(true, cacert6req, servercertreq, true); + DO_CTX_TEST(true, cacert7req, servercertreq, true); + + + /* Various good servers */ + DO_CTX_TEST(true, cacertreq, servercert1req, false); + DO_CTX_TEST(true, cacertreq, servercert2req, false); + DO_CTX_TEST(true, cacertreq, servercert3req, false); + DO_CTX_TEST(true, cacertreq, servercert4req, false); + DO_CTX_TEST(true, cacertreq, servercert5req, false); + DO_CTX_TEST(true, cacertreq, servercert6req, false); + DO_CTX_TEST(true, cacertreq, servercert7req, false); + + /* Bad servers */ + DO_CTX_TEST(true, cacertreq, servercert8req, true); + DO_CTX_TEST(true, cacertreq, servercert9req, true); + DO_CTX_TEST(true, cacertreq, servercert10req, true); + + /* Various good clients */ + DO_CTX_TEST(false, cacertreq, clientcert1req, false); + DO_CTX_TEST(false, cacertreq, clientcert2req, false); + DO_CTX_TEST(false, cacertreq, clientcert3req, false); + DO_CTX_TEST(false, cacertreq, clientcert4req, false); + DO_CTX_TEST(false, cacertreq, clientcert5req, false); + DO_CTX_TEST(false, cacertreq, clientcert6req, false); + DO_CTX_TEST(false, cacertreq, clientcert7req, false); + + /* Bad clients */ + DO_CTX_TEST(false, cacertreq, clientcert8req, true); + DO_CTX_TEST(false, cacertreq, clientcert9req, true); + DO_CTX_TEST(false, cacertreq, clientcert10req, true); + + + /* Expired stuff */ + DO_CTX_TEST(true, cacertexpreq, servercertreq, true); + DO_CTX_TEST(true, cacertreq, servercertexpreq, true); + DO_CTX_TEST(false, cacertreq, clientcertexpreq, true); + + + /* Not activated stuff */ + DO_CTX_TEST(true, cacertnewreq, servercertreq, true); + DO_CTX_TEST(true, cacertreq, servercertnewreq, true); + DO_CTX_TEST(false, cacertreq, clientcertnewreq, true); + + + DO_SESS_TEST(cacertreq, servercertreq, clientcertreq, false, false, "libvirt.org", NULL); + DO_SESS_TEST_EXT(cacertreq, cacert1req, servercertreq, clientcertreq, true, true, "libvirt.org", NULL); + + /* When an altname is set, the CN is ignored, so it must be duplicated + * as an altname for it to match */ + DO_SESS_TEST(cacertreq, servercertalt1req, clientcertreq, false, false, "libvirt.org", NULL); + DO_SESS_TEST(cacertreq, servercertalt1req, clientcertreq, false, false, "www.libvirt.org", NULL); + DO_SESS_TEST(cacertreq, servercertalt1req, clientcertreq, false, true, "wiki.libvirt.org", NULL); + + /* This intentionally doesn't replicate */ + DO_SESS_TEST(cacertreq, servercertalt2req, clientcertreq, false, true, "libvirt.org", NULL); + DO_SESS_TEST(cacertreq, servercertalt2req, clientcertreq, false, false, "www.libvirt.org", NULL); + DO_SESS_TEST(cacertreq, servercertalt2req, clientcertreq, false, false, "wiki.libvirt.org", NULL); + DO_SESS_TEST(cacertreq, servercertreq, clientcertreq, true, false, "libvirt.org", wildcards1); DO_SESS_TEST(cacertreq, servercertreq, clientcertreq, false, false, "libvirt.org", wildcards2); DO_SESS_TEST(cacertreq, servercertreq, clientcertreq, false, false, "libvirt.org", wildcards3); -- 1.7.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list