Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Jan 2020 04:33:46 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r357243 - head/lib/libpmc/pmu-events
Message-ID:  <202001290433.00T4XkI8087270@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Wed Jan 29 04:33:45 2020
New Revision: 357243
URL: https://svnweb.freebsd.org/changeset/base/357243

Log:
  libpmc: jevents: Go ahead and use snprintf(3)
  
  Reported by:	Coverity
  CID:		1391362

Modified:
  head/lib/libpmc/pmu-events/jevents.c

Modified: head/lib/libpmc/pmu-events/jevents.c
==============================================================================
--- head/lib/libpmc/pmu-events/jevents.c	Wed Jan 29 04:32:06 2020	(r357242)
+++ head/lib/libpmc/pmu-events/jevents.c	Wed Jan 29 04:33:45 2020	(r357243)
@@ -921,7 +921,8 @@ is_leaf_dir(const char *fpath)
 			char path[PATH_MAX];
 			struct stat st;
 
-			sprintf(path, "%s/%s", fpath, dir->d_name);
+			snprintf(path, sizeof(path), "%s/%s", fpath,
+			    dir->d_name);
 			if (stat(path, &st))
 				break;
 
@@ -1080,10 +1081,6 @@ process_one_file(const char *fpath, const struct stat 
 	return err;
 }
 
-#ifndef PATH_MAX
-#define PATH_MAX	4096
-#endif
-
 /*
  * Starting in directory 'start_dirname', find the "mapfile.csv" and
  * the set of JSON files for the architecture 'arch'.
@@ -1128,7 +1125,7 @@ main(int argc, char *argv[])
 		return 2;
 	}
 
-	sprintf(ldirname, "%s/%s", start_dirname, arch);
+	snprintf(ldirname, sizeof(ldirname), "%s/%s", start_dirname, arch);
 
 	/* If architecture does not have any event lists, bail out */
 	if (stat(ldirname, &stbuf) < 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202001290433.00T4XkI8087270>