aboutsummaryrefslogtreecommitdiff
path: root/src/sp/protocol/pubsub0/sub.c
diff options
context:
space:
mode:
authorKristóf Havasi <lnksz@users.noreply.github.com>2021-04-11 00:01:23 +0200
committerGitHub <noreply@github.com>2021-04-10 15:01:23 -0700
commit06ae767b12b8e26fecce6c882fec25911a98776c (patch)
treeb0bfb5b85126a784eb781ae476055eae81a1bd47 /src/sp/protocol/pubsub0/sub.c
parent7a0de1b25287f08b73c04d4f9c2834ae265cc382 (diff)
downloadnng-06ae767b12b8e26fecce6c882fec25911a98776c.tar.gz
nng-06ae767b12b8e26fecce6c882fec25911a98776c.tar.bz2
nng-06ae767b12b8e26fecce6c882fec25911a98776c.zip
fixes #1436 Guard against UB in sub0_ctx_subscribe (#1437)
In case sub0_ctx_subscribe is called to subscribe to _all_ topics
Diffstat (limited to 'src/sp/protocol/pubsub0/sub.c')
-rw-r--r--src/sp/protocol/pubsub0/sub.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/sp/protocol/pubsub0/sub.c b/src/sp/protocol/pubsub0/sub.c
index 9f3f2283..a40ee073 100644
--- a/src/sp/protocol/pubsub0/sub.c
+++ b/src/sp/protocol/pubsub0/sub.c
@@ -493,7 +493,9 @@ sub0_ctx_subscribe(void *arg, const void *buf, size_t sz, nni_type t)
NNI_FREE_STRUCT(new_topic);
return (NNG_ENOMEM);
}
- memcpy(new_topic->buf, buf, sz);
+ if (buf && new_topic->buf) {
+ memcpy(new_topic->buf, buf, sz);
+ }
new_topic->len = sz;
nni_list_append(&ctx->topics, new_topic);
nni_mtx_unlock(&sock->lk);