Message ID | 20231231053149.148563-1-m.belouarga@technologyandstrategy.com |
---|---|
State | Accepted |
Headers | show |
Series | Avoid giving invalid arguments to memcpy | expand |
Hi Mohamed, On 31.12.23 06:31, belouargamohamed@gmail.com wrote: > From: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com> > > Giving NULL pointer or size equal to 0 to memcpy can result in an undefined behaviour > > Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com> > --- > handlers/remote_handler.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/handlers/remote_handler.c b/handlers/remote_handler.c > index c4b83af..aa2b427 100644 > --- a/handlers/remote_handler.c > +++ b/handlers/remote_handler.c > @@ -48,7 +48,10 @@ static void RHset_payload(struct RHmsg *self, const void *body, size_t size) > { > zmq_msg_t *msg = &self->frame[FRAME_BODY]; > zmq_msg_init_size(msg, size); > - memcpy (zmq_msg_data(msg), body, size); > + if ((body != NULL) && (size > 0)) > + { > + memcpy (zmq_msg_data(msg), body, size); > + } > } > > static int RHmsg_send_cmd(struct RHmsg *self, void *request) Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/handlers/remote_handler.c b/handlers/remote_handler.c index c4b83af..aa2b427 100644 --- a/handlers/remote_handler.c +++ b/handlers/remote_handler.c @@ -48,7 +48,10 @@ static void RHset_payload(struct RHmsg *self, const void *body, size_t size) { zmq_msg_t *msg = &self->frame[FRAME_BODY]; zmq_msg_init_size(msg, size); - memcpy (zmq_msg_data(msg), body, size); + if ((body != NULL) && (size > 0)) + { + memcpy (zmq_msg_data(msg), body, size); + } } static int RHmsg_send_cmd(struct RHmsg *self, void *request)