dm: hw: Replace strlen with strnlen

Replace strlen function with strnlen function in device-model

Tracked-On: #2079
Signed-off-by: Long Liu <long.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Long Liu 2018-12-12 07:24:53 +00:00 committed by wenlingz
parent eab7cd47ae
commit 63b814e7e9
2 changed files with 3 additions and 2 deletions

View File

@ -2315,6 +2315,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
ret = 0;
#define MAX_OPTS_LEN 256
#ifdef AHCI_DEBUG
dbg = fopen("/tmp/log", "w+");
#endif
@ -2376,7 +2377,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
* Use parts of the md5 sum of the filename
*/
MD5_Init(&mdctx);
MD5_Update(&mdctx, opts, strlen(opts));
MD5_Update(&mdctx, opts, strnlen(opts, MAX_OPTS_LEN));
MD5_Final(digest, &mdctx);
rc = snprintf(ahci_dev->port[p].ident,
sizeof(ahci_dev->port[p].ident),

View File

@ -1006,7 +1006,7 @@ basl_make_templates(void)
tmpdir = _PATH_TMP;
}
len = strlen(tmpdir);
len = strnlen(tmpdir, MAXPATHLEN);
if ((len + sizeof(ASL_TEMPLATE) + 1) < MAXPATHLEN) {
strncpy(basl_template, tmpdir, len + 1);