Merge pull request #1765 from jameshilliard/rpc-add-calloc-null

Fix null pointer dereference in mg_rpc_add()
This commit is contained in:
Sergey Lyubka authored and GitHub committed 2022-09-25 23:22:57 +01:00
commit fb3b0ca6e3
2 files changed
+4

No files matched your search

+2
View File
@@ -3546,9 +3546,11 @@ void mg_mgr_init(struct mg_mgr *mgr) {
void mg_rpc_add(struct mg_rpc **head, struct mg_str method, void mg_rpc_add(struct mg_rpc **head, struct mg_str method,
void (*fn)(struct mg_rpc_req *), void *fn_data) { void (*fn)(struct mg_rpc_req *), void *fn_data) {
struct mg_rpc *rpc = (struct mg_rpc *) calloc(1, sizeof(*rpc)); struct mg_rpc *rpc = (struct mg_rpc *) calloc(1, sizeof(*rpc));
if (rpc != NULL) {
rpc->method = mg_strdup(method), rpc->fn = fn, rpc->fn_data = fn_data; rpc->method = mg_strdup(method), rpc->fn = fn, rpc->fn_data = fn_data;
rpc->next = *head, *head = rpc; rpc->next = *head, *head = rpc;
} }
}
void mg_rpc_del(struct mg_rpc **head, void (*fn)(struct mg_rpc_req *)) { void mg_rpc_del(struct mg_rpc **head, void (*fn)(struct mg_rpc_req *)) {
struct mg_rpc *r; struct mg_rpc *r;
+2
View File
@@ -3,9 +3,11 @@
void mg_rpc_add(struct mg_rpc **head, struct mg_str method, void mg_rpc_add(struct mg_rpc **head, struct mg_str method,
void (*fn)(struct mg_rpc_req *), void *fn_data) { void (*fn)(struct mg_rpc_req *), void *fn_data) {
struct mg_rpc *rpc = (struct mg_rpc *) calloc(1, sizeof(*rpc)); struct mg_rpc *rpc = (struct mg_rpc *) calloc(1, sizeof(*rpc));
if (rpc != NULL) {
rpc->method = mg_strdup(method), rpc->fn = fn, rpc->fn_data = fn_data; rpc->method = mg_strdup(method), rpc->fn = fn, rpc->fn_data = fn_data;
rpc->next = *head, *head = rpc; rpc->next = *head, *head = rpc;
} }
}
void mg_rpc_del(struct mg_rpc **head, void (*fn)(struct mg_rpc_req *)) { void mg_rpc_del(struct mg_rpc **head, void (*fn)(struct mg_rpc_req *)) {
struct mg_rpc *r; struct mg_rpc *r;