diff mbox series

[libubootenv,3/6] Fix coverity #293495 and #293497

Message ID 20200628151336.952051-3-sbabic@denx.de
State Accepted
Headers show
Series [libubootenv,1/6] Add coverity setup for Travis | expand

Commit Message

Stefano Babic June 28, 2020, 3:13 p.m. UTC
Buffer not null terminated in strncpy(), initializes to 0.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 src/uboot_env.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/uboot_env.c b/src/uboot_env.c
index f92977b..8086463 100644
--- a/src/uboot_env.c
+++ b/src/uboot_env.c
@@ -1147,7 +1147,8 @@  int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
 			ctx->size = dev->envsize;
 
 		if (tmp) {
-			strncpy(dev->devname, tmp, sizeof(dev->devname));
+			memset(dev->devname, 0, sizeof(dev->devname));
+			strncpy(dev->devname, tmp, sizeof(dev->devname) - 1);
 			free(tmp);
 		}
 
@@ -1323,7 +1324,8 @@  int libuboot_configure(struct uboot_ctx *ctx,
 		for (i = 0; i < 2; i++, envdevs++, dev++) {
 			if (!envdevs)
 				break;
-			strncpy(dev->devname, envdevs->devname, sizeof(dev->devname));
+			memset(dev->devname, 0, sizeof(dev->devname));
+			strncpy(dev->devname, envdevs->devname, sizeof(dev->devname) - 1);
 			dev->envsize = envdevs->envsize;
 			dev->sectorsize = envdevs->sectorsize;
 			dev->envsectors = envdevs->envsectors;