Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: fix usage of strncpy #618

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/remoteproc/remoteproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,12 @@ void remoteproc_init_mem(struct remoteproc_mem *mem, const char *name,
{
if (!mem || !io || size == 0)
return;
if (name)
strncpy(mem->name, name, sizeof(mem->name));
else
if (name) {
strncpy(mem->name, name, sizeof(mem->name) - 1);
mem->name[sizeof(mem->name) - 1] = 0;
} else {
mem->name[0] = 0;
}
mem->pa = pa;
mem->da = da;
mem->io = io;
Expand Down
6 changes: 4 additions & 2 deletions lib/rpmsg/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags)

ns_msg.flags = flags;
ns_msg.addr = ept->addr;
strncpy(ns_msg.name, ept->name, sizeof(ns_msg.name));
strncpy(ns_msg.name, ept->name, sizeof(ns_msg.name) - 1);
ns_msg.name[sizeof(ns_msg.name) - 1] = '\0';
ret = rpmsg_send_offchannel_raw(ept, ept->addr,
RPMSG_NS_EPT_ADDR,
&ns_msg, sizeof(ns_msg), true);
Expand Down Expand Up @@ -305,7 +306,8 @@ void rpmsg_register_endpoint(struct rpmsg_device *rdev,
rpmsg_ept_cb cb,
rpmsg_ns_unbind_cb ns_unbind_cb, void *priv)
{
strncpy(ept->name, name ? name : "", sizeof(ept->name));
strncpy(ept->name, name ? name : "", sizeof(ept->name) - 1);
ept->name[sizeof(ept->name) - 1] = '\0';
ept->refcnt = 1;
ept->addr = src;
ept->dest_addr = dest;
Expand Down
Loading