summaryrefslogtreecommitdiff
path: root/0058-empty-pointer-check-in-lcr_rt_ops.patch
blob: 1cbe4b23e090afb23aa893530df9c8661c4c5a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
From ea1bc00c894a3717ea375f5ff40c3eb05447ae17 Mon Sep 17 00:00:00 2001
From: jikai <jikai11@huawei.com>
Date: Sat, 13 Apr 2024 14:07:33 +0000
Subject: [PATCH 58/69] empty pointer check in lcr_rt_ops

Signed-off-by: jikai <jikai11@huawei.com>
---
 .../modules/runtime/engines/lcr/lcr_rt_ops.c  | 84 ++++++++++++++++++-
 1 file changed, 81 insertions(+), 3 deletions(-)

diff --git a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
index 978da079..a89d0375 100644
--- a/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
+++ b/src/daemon/modules/runtime/engines/lcr/lcr_rt_ops.c
@@ -53,6 +53,11 @@ int rt_lcr_create(const char *name, const char *runtime, const rt_create_params_
     char *runtime_root = NULL;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     if (conf_get_systemd_cgroup()) {
         ERROR("Systemd cgroup not supported for lcr runtime");
         isulad_set_error_message("Systemd cgroup not supported for lcr runtime");
@@ -129,6 +134,11 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
     struct engine_operation *engine_ops = NULL;
     engine_start_request_t request = { 0 };
 
+    if (name == NULL || runtime == NULL || params == NULL || pid_info == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_start_op == NULL) {
         ERROR("Failed to get engine start operations");
@@ -183,6 +193,11 @@ int rt_lcr_clean_resource(const char *name, const char *runtime, const rt_clean_
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_clean_op == NULL) {
         ERROR("Failed to get engine clean operations");
@@ -236,6 +251,15 @@ int rt_lcr_rm(const char *name, const char *runtime, const rt_rm_params_t *param
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+    if (params->rootpath == NULL) {
+        ERROR("Missing root path");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_delete_op == NULL) {
         // if engine_ops is NULL, container root path may have been corrupted, try to remove by daemon
@@ -284,6 +308,11 @@ int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_
     int nret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL || status == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_get_container_status_op == NULL) {
         ERROR("Failed to get engine status operations");
@@ -322,6 +351,11 @@ int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats
     int nret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL || rs_stats == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_get_container_resources_stats_op == NULL) {
         ERROR("Failed to get engine stats operations");
@@ -451,6 +485,11 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
     char *user = NULL;
     char *add_gids = NULL;
 
+    if (id == NULL || runtime == NULL || params == NULL || exit_code == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_exec_op == NULL) {
         DEBUG("Failed to get engine exec operations");
@@ -519,6 +558,11 @@ int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_pause_op == NULL) {
         DEBUG("Failed to get engine pause operations");
@@ -549,6 +593,11 @@ int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_resume_op == NULL) {
         DEBUG("Failed to get engine resume operations");
@@ -579,6 +628,11 @@ int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Null argument");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_console_op == NULL) {
         DEBUG("Failed to get engine attach operations");
@@ -641,6 +695,11 @@ int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t
     struct engine_operation *engine_ops = NULL;
     struct engine_cgroup_resources cr = { 0 };
 
+    if (id == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_update_op == NULL) {
         DEBUG("Failed to get engine update operations");
@@ -673,10 +732,9 @@ int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_par
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
-    if (out == NULL) {
+    if (name == NULL || runtime == NULL || params == NULL || out == NULL) {
         ERROR("Invalid arguments");
-        ret = -1;
-        goto out;
+        return -1;
     }
 
     engine_ops = engines_get_handler(runtime);
@@ -709,6 +767,11 @@ int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (id == NULL || runtime == NULL || params == NULL) {
+        ERROR("Invalid arguments");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) {
         DEBUG("Failed to get engine resume operations");
@@ -740,6 +803,11 @@ int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize
     int ret = 0;
     struct engine_operation *engine_ops = NULL;
 
+    if (id == NULL || runtime == NULL || params == NULL) {
+        ERROR("Nullptr arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) {
         DEBUG("Failed to get engine resume operations");
@@ -767,6 +835,11 @@ out:
 
 int rt_lcr_kill(const char *id, const char *runtime, const rt_kill_params_t *params)
 {
+    if (id == NULL || runtime == NULL || params == NULL || params->pid < 0) {
+        ERROR("Invalid arguments not allowed");
+        return -1;
+    }
+
     if (util_process_alive(params->pid, params->start_time) == false) {
         if (params->signal == params->stop_signal || params->signal == SIGKILL) {
             WARN("Process %d is not alive", params->pid);
@@ -798,6 +871,11 @@ int rt_lcr_rebuild_config(const char *name, const char *runtime, const rt_rebuil
     oci_runtime_spec *oci_spec = NULL;
     __isula_auto_free parser_error err = NULL;
 
+    if (name == NULL || runtime == NULL || params == NULL) {
+        ERROR("Invalid arguments not allowed");
+        return -1;
+    }
+
     engine_ops = engines_get_handler(runtime);
     if (engine_ops == NULL || engine_ops->engine_create_op == NULL) {
         ERROR("Failed to get engine rebuild config operations");
-- 
2.34.1