]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
test: initialize capture structure before freeing
authorPhilip Prindeville <philipp@redfish-solutions.com>
Fri, 16 Sep 2022 03:35:21 +0000 (21:35 -0600)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Mon, 26 Sep 2022 13:55:33 +0000 (08:55 -0500)
ASTERISK-30232 #close

Change-Id: I2603e2cef8f93f6b0a6ef39f7eac744251bb3902

include/asterisk/test.h
main/test.c
tests/test_crypto.c

index 12aed650be3a7db47461a9d6578fca8bd09c83c3..d2be92c6fd1a90b3bd6e17f103124ae86bba4590 100644 (file)
@@ -438,6 +438,16 @@ int __ast_test_status_update(const char *file, const char *func, int line, struc
        } \
 })
 
+/*!
+ * \brief Initialize the capture structure.
+ *
+ * \since 16.30.0, 18.16.0, 19.8.0, 20.1.0
+ *
+ * \param capture The structure describing the child process and its
+ * associated output.
+ */
+void ast_test_capture_init(struct ast_test_capture *capture);
+
 /*!
  * \brief Release the storage (buffers) associated with capturing
  * the output of an external child process.
index 03de33bce96e89366935ea1f653dfdd2811cc462..f06b55718bde42bf5b26357128b4a6b3c04d73b0 100644 (file)
@@ -313,6 +313,12 @@ void ast_test_set_result(struct ast_test *test, enum ast_test_result_state state
        test->state = state;
 }
 
+void ast_test_capture_init(struct ast_test_capture *capture)
+{
+       capture->outbuf = capture->errbuf = NULL;
+       capture->pid = capture->exitcode = -1;
+}
+
 void ast_test_capture_free(struct ast_test_capture *capture)
 {
        if (capture) {
@@ -336,8 +342,7 @@ int ast_test_capture_command(struct ast_test_capture *capture, const char *file,
        int status = 0;
        FILE *cmd = NULL, *out = NULL, *err = NULL;
 
-       memset(capture, 0, sizeof(*capture));
-       capture->pid = capture->exitcode = -1;
+       ast_test_capture_init(capture);
 
        if (data != NULL && datalen > 0) {
                if (pipe(fd0) == -1) {
index a3a0004b3ce49ab943c4428b0c381045ae0dc419..1eec181b99fa7c9ec2186edaaa41912e5da7d2be 100644 (file)
@@ -105,6 +105,8 @@ AST_TEST_DEFINE(crypto_rsa_encrypt)
 
        ast_test_status_update(test, "Executing RSA encryption test\n");
 
+       ast_test_capture_init(&cap);
+
        if (!ast_check_command_in_path(command)) {
                ast_test_status_update(test, "couldn't find %s\n", command);
                return res;
@@ -190,6 +192,8 @@ AST_TEST_DEFINE(crypto_rsa_decrypt)
 
        ast_test_status_update(test, "Executing RSA decryption test\n");
 
+       ast_test_capture_init(&cap);
+
        if (!ast_check_command_in_path(command)) {
                ast_test_status_update(test, "couldn't find %s\n", command);
                return res;
@@ -285,6 +289,8 @@ AST_TEST_DEFINE(crypto_sign)
 
        ast_test_status_update(test, "Executing RSA signing test\n");
 
+       ast_test_capture_init(&cap);
+
        if (!ast_check_command_in_path(command)) {
                ast_test_status_update(test, "couldn't find %s\n", command);
                return res;
@@ -396,6 +402,8 @@ AST_TEST_DEFINE(crypto_verify)
 
        ast_test_status_update(test, "Executing RSA signature verification test\n");
 
+       ast_test_capture_init(&cap);
+
        if (!ast_check_command_in_path(command)) {
                ast_test_status_update(test, "couldn't find %s\n", command);
                return res;
@@ -491,6 +499,8 @@ AST_TEST_DEFINE(crypto_aes_encrypt)
 
        ast_test_status_update(test, "Executing AES-ECB encryption test\n");
 
+       ast_test_capture_init(&cap);
+
        if (!ast_check_command_in_path(command)) {
                ast_test_status_update(test, "couldn't find %s\n", command);
                return res;
@@ -565,6 +575,8 @@ AST_TEST_DEFINE(crypto_aes_decrypt)
 
        ast_test_status_update(test, "Executing AES-ECB decryption test\n");
 
+       ast_test_capture_init(&cap);
+
        if (!ast_check_command_in_path(command)) {
                ast_test_status_update(test, "couldn't find %s\n", command);
                return res;