1 /*
2 * Copyright (C) 2018-2026 Red Hat, Inc. All rights reserved.
3 *
4 * Author: Fabio M. Di Nitto <fabbione@kronosnet.org>
5 *
6 * This software licensed under GPL-2.0+
7 */
8
9 #include "config.h"
10
11 #include <string.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <errno.h>
16 #include <stdint.h>
17 #include <limits.h>
18 #include <sys/socket.h>
19
20 #include "test-common.h"
21
22 static int test(void)
23 {
24 int err = 0;
25 char *error_string = NULL;
26
27 printf("Testing execute_bin_sh_command\n");
28
29 printf("command true\n");
|
(1) Event alloc_arg: |
"execute_bin_sh_command" allocates memory that is stored into "error_string". [details] |
|
(2) Event path: |
Condition "(_foe_res = execute_bin_sh_command("true", &error_string)) != 0", taking true branch. |
|
(3) Event path: |
Jumping to label "out_clean". |
| Also see events: |
[leaked_storage] |
30 FAIL_ON_ERR(execute_bin_sh_command("true", &error_string));
31 if (error_string) {
32 printf("Error string: %s\n", error_string);
33 free(error_string);
34 error_string = NULL;
35 }
36
37 printf("command false\n");
38 err = execute_bin_sh_command("false", &error_string);
39 if (error_string) {
40 printf("Error string: %s\n", error_string);
41 free(error_string);
42 error_string = NULL;
43 }
44 if (!err) {
45 printf("*** FAIL on line %d. Can we really execute false successfully?!?!\n", __LINE__);
46 err = -1;
47 goto out_clean;
48 }
49
50 printf("command that outputs to stdout (enforcing redirect)\n");
51 err = execute_bin_sh_command("grep -h 2>&1", &error_string);
52 if (error_string) {
53 printf("Error string: %s\n", error_string);
54 free(error_string);
55 error_string = NULL;
56 }
57 if (!err) {
58 printf("*** FAIL on line %d. Can we really execute grep -h successfully?!?\n", __LINE__);
59 err = -1;
60 goto out_clean;
61 }
62
63 printf("command that outputs to stderr\n");
64 err = execute_bin_sh_command("grep -h", &error_string);
65 if (error_string) {
66 printf("Error string: %s\n", error_string);
67 free(error_string);
68 error_string = NULL;
69 }
70 if (!err) {
71 printf("*** FAIL on line %d. Can we really execute grep -h successfully?!?\n", __LINE__);
72 err = -1;
73 goto out_clean;
74 }
75
76 printf("Testing ERROR conditions\n");
77
78 printf("empty command\n");
79 FAIL_ON_SUCCESS(execute_bin_sh_command(NULL, &error_string), EINVAL);
80 if (error_string) {
81 printf("Error string: %s\n", error_string);
82 free(error_string);
83 error_string = NULL;
84 }
85
86 printf("empty error\n");
87 FAIL_ON_SUCCESS(execute_bin_sh_command("true", NULL), EINVAL);
88
89 err = 0;
90
91 out_clean:
92
|
CID (unavailable; MK=c066f7a4b403e6c5058a4a8b51d2bdf7) (#1 of 1): Resource leak (RESOURCE_LEAK): |
|
(4) Event leaked_storage: |
Variable "error_string" going out of scope leaks the storage it points to. |
| Also see events: |
[alloc_arg] |
93 return err;
94 }
95
96 int main(void)
97 {
98 need_root();
99
100 if (test() < 0)
101 return FAIL;
102
103 return PASS;
104 }
105