5cfeb91
From 2c76660566d026d430305231e72c259372de4380 Mon Sep 17 00:00:00 2001
5cfeb91
From: Lubomir Rintel <lkundrak@v3.sk>
5cfeb91
Date: Wed, 4 Dec 2013 23:17:10 +0100
5cfeb91
Subject: [PATCH] Fix build with -Werror=format-security
5cfeb91
5cfeb91
Fedora, starting with version 21, will enable this flag in order to limit
5cfeb91
potentially insecure uses of format strings. It is required for format strings
5cfeb91
to be constant now.
5cfeb91
---
5cfeb91
 cmdline/cmdline_afp.c     |  4 ++--
5cfeb91
 cmdline/cmdline_testafp.c | 12 ++++++------
5cfeb91
 fuse/client.c             |  5 +----
5cfeb91
 fuse/commands.c           |  4 ++--
5cfeb91
 lib/afp_url.c             | 12 ++++++------
5cfeb91
 5 files changed, 17 insertions(+), 20 deletions(-)
5cfeb91
5cfeb91
diff --git a/cmdline/cmdline_afp.c b/cmdline/cmdline_afp.c
5cfeb91
index 827150b..59f0977 100644
5cfeb91
--- a/cmdline/cmdline_afp.c
5cfeb91
+++ b/cmdline/cmdline_afp.c
5cfeb91
@@ -828,11 +828,11 @@ int com_status(char * arg)
5cfeb91
 	char text[40960];
5cfeb91
 
5cfeb91
 	afp_status_header(text,&len;;
5cfeb91
-	printf(text);
5cfeb91
+	printf("%s", text);
5cfeb91
 
5cfeb91
 	len=40960;
5cfeb91
 	afp_status_server(server,text,&len;;
5cfeb91
-	printf(text);
5cfeb91
+	printf("%s", text);
5cfeb91
 	return 0;
5cfeb91
 }
5cfeb91
 
5cfeb91
diff --git a/cmdline/cmdline_testafp.c b/cmdline/cmdline_testafp.c
5cfeb91
index c40f2bd..f887aec 100644
5cfeb91
--- a/cmdline/cmdline_testafp.c
5cfeb91
+++ b/cmdline/cmdline_testafp.c
5cfeb91
@@ -26,12 +26,12 @@ static int test_one_url(char * url_string,
5cfeb91
 	struct afp_url valid_url;
5cfeb91
 	afp_default_url(&valid_url);
5cfeb91
 	valid_url.protocol=protocol;
5cfeb91
-	sprintf(valid_url.servername,servername);
5cfeb91
-	sprintf(valid_url.volumename,volumename);
5cfeb91
-	sprintf(valid_url.path,path);
5cfeb91
-	sprintf(valid_url.username,username);
5cfeb91
-	sprintf(valid_url.password,password);
5cfeb91
-	sprintf(valid_url.uamname,uamname);
5cfeb91
+	snprintf(valid_url.servername,sizeof(valid_url.servername),"%s",servername);
5cfeb91
+	snprintf(valid_url.volumename,sizeof(valid_url.volumename),"%s",volumename);
5cfeb91
+	snprintf(valid_url.path,sizeof(valid_url.path),"%s",path);
5cfeb91
+	snprintf(valid_url.username,sizeof(valid_url.username),"%s",username);
5cfeb91
+	snprintf(valid_url.password,sizeof(valid_url.password),"%s",password);
5cfeb91
+	snprintf(valid_url.uamname,(valid_url.uamname),"%s",uamname);
5cfeb91
 	valid_url.port=port;
5cfeb91
 
5cfeb91
 	if (afp_url_validate(url_string,&valid_url)) 
5cfeb91
diff --git a/fuse/client.c b/fuse/client.c
5cfeb91
index f795ca6..d19e9ef 100644
5cfeb91
--- a/fuse/client.c
5cfeb91
+++ b/fuse/client.c
5cfeb91
@@ -509,7 +509,6 @@ static int prepare_buffer(int argc, char * argv[])
5cfeb91
 int read_answer(int sock) {
5cfeb91
 	int len=0, expected_len=0, packetlen;
5cfeb91
 	char incoming_buffer[MAX_CLIENT_RESPONSE];
5cfeb91
-	char toprint[MAX_CLIENT_RESPONSE+200];
5cfeb91
 	struct timeval tv;
5cfeb91
 	fd_set rds,ords;
5cfeb91
 	int ret;
5cfeb91
@@ -546,9 +545,7 @@ int read_answer(int sock) {
5cfeb91
 	}
5cfeb91
 
5cfeb91
 done:
5cfeb91
-	memset(toprint,0,MAX_CLIENT_RESPONSE+200);
5cfeb91
-	snprintf(toprint,MAX_CLIENT_RESPONSE+200,"%s",incoming_buffer+sizeof(*answer));
5cfeb91
-	printf(toprint);
5cfeb91
+	printf("%.200s",incoming_buffer+sizeof(*answer));
5cfeb91
 	return ((struct afp_server_response *) incoming_buffer)->result;
5cfeb91
 
5cfeb91
 	return 0;
5cfeb91
diff --git a/fuse/commands.c b/fuse/commands.c
5cfeb91
index aa7444d..bb06928 100644
5cfeb91
--- a/fuse/commands.c
5cfeb91
+++ b/fuse/commands.c
5cfeb91
@@ -163,6 +163,7 @@ static void fuse_log_for_client(void * priv,
5cfeb91
 		len = strlen(c->client_string);
5cfeb91
 		snprintf(c->client_string+len,
5cfeb91
 			MAX_CLIENT_RESPONSE-len,
5cfeb91
+			"%s",
5cfeb91
 			message);
5cfeb91
 	} else {
5cfeb91
 
5cfeb91
@@ -468,7 +468,7 @@ static int process_mount(struct fuse_client * c)
5cfeb91
 	volume->mapping=req->map;
5cfeb91
 	afp_detect_mapping(volume);
5cfeb91
 
5cfeb91
-	snprintf(volume->mountpoint,255,req->mountpoint);
5cfeb91
+	snprintf(volume->mountpoint,255,"%s",req->mountpoint);
5cfeb91
 
5cfeb91
 	/* Create the new thread and block until we get an answer back */
5cfeb91
 	{
5cfeb91
diff --git a/lib/afp_url.c b/lib/afp_url.c
5cfeb91
index 42bac1c..f152d7b 100644
5cfeb91
--- a/lib/afp_url.c
5cfeb91
+++ b/lib/afp_url.c
5cfeb91
@@ -233,7 +233,7 @@ int afp_parse_url(struct afp_url * url, const char * toparse, int verbose)
5cfeb91
 		}
5cfeb91
 	}
5cfeb91
 
5cfeb91
-	snprintf(url->servername,strlen(p)+1,p);
5cfeb91
+	snprintf(url->servername,strlen(p)+1,"%s",p);
5cfeb91
 	if (check_servername(url->servername)) {
5cfeb91
 			if (verbose) printf("This isn't a valid servername\n");
5cfeb91
 			return -1;
5cfeb91
@@ -263,7 +263,7 @@ int afp_parse_url(struct afp_url * url, const char * toparse, int verbose)
5cfeb91
 	if ((q=escape_strrchr(p,':',":"))) {
5cfeb91
 		*q='\0';
5cfeb91
 		q++;
5cfeb91
-		snprintf(url->password,strlen(q)+1,q);
5cfeb91
+		snprintf(url->password,strlen(q)+1,"%s",q);
5cfeb91
 		if (check_password(url->password)) {
5cfeb91
 			if (verbose) printf("This isn't a valid passwd\n");
5cfeb91
 			return -1;
5cfeb91
@@ -276,7 +276,7 @@ int afp_parse_url(struct afp_url * url, const char * toparse, int verbose)
5cfeb91
 	if ((q=strstr(p,";AUTH="))) {
5cfeb91
 		*q='\0';
5cfeb91
 		q+=6;
5cfeb91
-		snprintf(url->uamname,strlen(q)+1,q);
5cfeb91
+		snprintf(url->uamname,strlen(q)+1,"%s",q);
5cfeb91
 		if (check_uamname(url->uamname)) {
5cfeb91
 			if (verbose) printf("This isn't a valid uamname\n");
5cfeb91
 			return -1;
5cfeb91
@@ -284,7 +284,7 @@ int afp_parse_url(struct afp_url * url, const char * toparse, int verbose)
5cfeb91
 	}
5cfeb91
 
5cfeb91
 	if (strlen(p)>0) {
5cfeb91
-		snprintf(url->username,strlen(p)+1,p);
5cfeb91
+		snprintf(url->username,strlen(p)+1,"%s",p);
5cfeb91
 		if (check_username(url->username)) {
5cfeb91
 			if (verbose) printf("This isn't a valid username\n");
5cfeb91
 			return -1;;
5cfeb91
@@ -304,12 +304,12 @@ parse_secondpart:
5cfeb91
 		*q='\0';
5cfeb91
 		q++;
5cfeb91
 	}
5cfeb91
-	snprintf(url->volumename,strlen(p)+1,p);
5cfeb91
+	snprintf(url->volumename,strlen(p)+1,"%s",p);
5cfeb91
 
5cfeb91
 
5cfeb91
 	if (q) {
5cfeb91
 		url->path[0]='/';
5cfeb91
-		snprintf(url->path+1,strlen(q)+1,q);
5cfeb91
+		snprintf(url->path+1,strlen(q)+1,"%s",q);
5cfeb91
 	}
5cfeb91
 
5cfeb91
 done:
5cfeb91
-- 
5cfeb91
1.8.4.2
5cfeb91