From 091f36e428024c27b1f2bd69853179d2b469ea1b Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Mon, 23 Jul 2018 08:35:57 +0200 Subject: [PATCH] ioconf.c: Fix more gcc format-truncation warnings Signed-off-by: Sebastien GODARD --- ioconf.c | 8 ++++---- ioconf.h | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ioconf.c b/ioconf.c index fa5fd99..940b0c5 100644 --- a/ioconf.c +++ b/ioconf.c @@ -219,7 +219,7 @@ int ioc_init(void) } else { IOC_ALLOC(iocp->desc, char, IOC_DESCLEN); - strncpy(iocp->desc, desc, IOC_DESCLEN - 1); + memcpy(iocp->desc, desc, IOC_DESCLEN); } ioc_refnr[indirect]++; ioconf[major] = iocp; @@ -300,8 +300,8 @@ int ioc_init(void) /* basename of device + provided string + controller # */ if (*cfmt == '*') { - strncpy(blkp->cfmt, blkp->name, IOC_FMTLEN - 1); - blkp->cfmt[IOC_FMTLEN - 1] = '\0'; + strncpy(blkp->cfmt, blkp->name, sizeof(blkp->cfmt) - 1); + blkp->cfmt[sizeof(blkp->cfmt) - 1] = '\0'; } else { sprintf(blkp->cfmt, "%s%s%%d", blkp->name, cfmt); @@ -337,7 +337,7 @@ int ioc_init(void) iocp->desc = NULL; iocp->basemajor = major; ioconf[major] = iocp; - strncpy(blkp->desc, desc, IOC_DESCLEN - 1); + memcpy(blkp->desc, desc, IOC_DESCLEN); blkp = NULL; iocp = NULL; ++count; } diff --git a/ioconf.h b/ioconf.h index 88c5466..15af348 100644 --- a/ioconf.h +++ b/ioconf.h @@ -15,6 +15,7 @@ #define IOC_DEVLEN 48 #define IOC_LINESIZ 256 #define IOC_FMTLEN 16 +#define IOC_XFMTLEN (IOC_FMTLEN + IOC_NAMELEN + 3) #ifndef MINORBITS #define MINORBITS 20 @@ -50,9 +51,9 @@ struct blk_config { char name[IOC_NAMELEN]; /* device basename */ - char cfmt[IOC_FMTLEN]; /* controller format string */ + char cfmt[IOC_XFMTLEN]; /* controller format string */ char dfmt[IOC_FMTLEN]; /* disk format string */ - char pfmt[IOC_FMTLEN]; /* partition format string */ + char pfmt[IOC_FMTLEN + 2]; /* partition format string */ /* ctrlno is in the ioc_entry */ unsigned int ctrl_explicit; /* use "cN" in name */ unsigned int dcount; /* number of devices handled by this major */ -- 2.40.0