diff mbox series

Fix coverity #292459

Message ID 20200412131214.12932-1-sbabic@denx.de
State Accepted
Headers show
Series Fix coverity #292459 | expand

Commit Message

Stefano Babic April 12, 2020, 1:12 p.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/cpio_utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index dc6d508..ca67cb2 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -643,7 +643,7 @@  int copyimage(void *out, struct img_type *img, writeimage callback)
 
 int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset)
 {
-	unsigned char buf[256];
+	unsigned char buf[sizeof(fhdr->filename)];
 	if (fill_buffer(fd, buf, sizeof(struct new_ascii_header), offset, NULL, NULL) < 0)
 		return -EINVAL;
 	if (get_cpiohdr(buf, &fhdr->size, &fhdr->namesize, &fhdr->chksum) < 0) {
@@ -658,6 +658,7 @@  int extract_cpio_header(int fd, struct filehdr *fhdr, unsigned long *offset)
 		return -EINVAL;
 	}
 
+	buf[fhdr->namesize] = '\0';
 	if (fill_buffer(fd, buf, fhdr->namesize , offset, NULL, NULL) < 0)
 		return -EINVAL;
 	strlcpy(fhdr->filename, (char *)buf, sizeof(fhdr->filename));