Skip to content

Commit c31b16e

Browse files
author
roman
committed
messages client BUGFIX excluded_change null deref
1 parent 6dfdc0d commit c31b16e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/messages_client.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ nc_rpc_establishpush_onchange(const char *datastore, const char *filter, const c
698698
{
699699
struct nc_rpc_establishpush *rpc;
700700
uint32_t i;
701+
void *tmp;
701702

702703
NC_CHECK_ARG_RET(NULL, datastore, NULL);
703704

@@ -737,7 +738,15 @@ nc_rpc_establishpush_onchange(const char *datastore, const char *filter, const c
737738
if (excluded_change && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
738739
rpc->excluded_change = NULL;
739740
for (i = 0; excluded_change[i]; ++i) {
740-
rpc->excluded_change = realloc(rpc->excluded_change, (i + 2) * sizeof *rpc->excluded_change);
741+
tmp = realloc(rpc->excluded_change, (i + 2) * sizeof *rpc->excluded_change);
742+
if (!tmp) {
743+
/* in case we fail to alloc, just free all the excluded changes, but return the rpc anyways */
744+
ERRMEM;
745+
free(rpc->excluded_change);
746+
rpc->excluded_change = NULL;
747+
break;
748+
}
749+
rpc->excluded_change = tmp;
741750
rpc->excluded_change[i] = strdup(excluded_change[i]);
742751
rpc->excluded_change[i + 1] = NULL;
743752
}

0 commit comments

Comments
 (0)