cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH] glocktop: Fix new -Wformat-overflow warnings
@ 2018-04-10 11:33 Andrew Price
  2018-04-10 13:05 ` Bob Peterson
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Price @ 2018-04-10 11:33 UTC (permalink / raw)
  To: cluster-devel.redhat.com

Fixes new warnings in glocktop that appeared in Fedora 28 (gcc 8.0.1 /
glibc 2.27), e.g.:

  glocktop.c:1806:30: warning: '_waiters' directive writing 8 bytes
  into a region of size between 2 and 4091 [-Wformat-overflow=]

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/glocktop/glocktop.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/gfs2/glocktop/glocktop.c b/gfs2/glocktop/glocktop.c
index 0305d3dd..7d65ac4a 100644
--- a/gfs2/glocktop/glocktop.c
+++ b/gfs2/glocktop/glocktop.c
@@ -921,7 +921,7 @@ static void show_dlm_grants(int locktype, const char *g_line, int dlmgrants,
 			    int summary)
 {
 	int i;
-	char dlm_resid[64];
+	char dlm_resid[75];
 	unsigned int lkb_id, lkbnodeid, remid, ownpid, exflags, flags, status;
 	unsigned int grmode, rqmode, nodeid, length;
 	unsigned long long xid, us;
@@ -1596,7 +1596,7 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters,
 			      int dlmgrants, int trace_dir_path,
 			      int show_held, int help, int summary)
 {
-	char fstitle[96], fsdlm[96];
+	char fstitle[96], fsdlm[105];
 	char ctimestr[64];
 	time_t t;
 	int i;
@@ -1652,7 +1652,7 @@ int main(int argc, char **argv)
 {
 	int fd;
 	DIR *dir = NULL;
-	char fn[PATH_MAX];
+	char *fn;
 	struct dirent *dent;
 	int retval;
 	int refresh_time = REFRESH_TIME;
@@ -1772,8 +1772,12 @@ int main(int argc, char **argv)
 	while (!done) {
 		struct timeval tv;
 
-		sprintf(fn, "%s/gfs2/", debugfs);
+		if (asprintf(&fn, "%s/gfs2/", debugfs) == -1) {
+			perror(argv[0]);
+			exit(-1);
+		}
 		dir = opendir(fn);
+		free(fn);
 
 		if (!dir) {
 			if (interactive) {
@@ -1787,7 +1791,7 @@ int main(int argc, char **argv)
 		display_title_lines();
 		while ((dent = readdir(dir))) {
 			const char *fsname;
-			char dlm_fn[PATH_MAX];
+			char dlm_fn[PATH_MAX+5+8]; /* "/dlm/" and "_waiters" */
 			FILE *dlmf;
 			int dlmfd;
 
@@ -1822,8 +1826,10 @@ int main(int argc, char **argv)
 				}
 			}
 
-			sprintf(fn, "%s/gfs2/%s/glocks", debugfs,
-				dent->d_name);
+			if (asprintf(&fn, "%s/gfs2/%s/glocks", debugfs, dent->d_name) == -1) {
+				perror(argv[0]);
+				exit(-1);
+			}
 			fd = open(fn, O_RDONLY);
 			if (fd < 0) {
 				if (interactive) {
@@ -1831,8 +1837,10 @@ int main(int argc, char **argv)
 					endwin();
 				}
 				perror(fn);
+				free(fn);
 				exit(-1);
 			}
+			free(fn);
 			parse_glocks_file(fd, fsname, dlmwaiters, dlmgrants,
 					  trace_dir_path, show_held, help,
 					  summary);
-- 
2.16.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Cluster-devel] [PATCH] glocktop: Fix new -Wformat-overflow warnings
  2018-04-10 11:33 [Cluster-devel] [PATCH] glocktop: Fix new -Wformat-overflow warnings Andrew Price
@ 2018-04-10 13:05 ` Bob Peterson
  0 siblings, 0 replies; 2+ messages in thread
From: Bob Peterson @ 2018-04-10 13:05 UTC (permalink / raw)
  To: cluster-devel.redhat.com

----- Original Message -----
> Fixes new warnings in glocktop that appeared in Fedora 28 (gcc 8.0.1 /
> glibc 2.27), e.g.:
> 
>   glocktop.c:1806:30: warning: '_waiters' directive writing 8 bytes
>   into a region of size between 2 and 4091 [-Wformat-overflow=]
> 
> Signed-off-by: Andrew Price <anprice@redhat.com>
> ---
>  gfs2/glocktop/glocktop.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)

Hi,

Looks good. ACK.

Regards,

Bob Peterson
Red Hat File Systems



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-10 13:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-10 11:33 [Cluster-devel] [PATCH] glocktop: Fix new -Wformat-overflow warnings Andrew Price
2018-04-10 13:05 ` Bob Peterson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).