diff mbox series

sunrpc: avoid -Wformat-security warning

Message ID 20240719105504.1547187-1-arnd@kernel.org (mailing list archive)
State New
Headers show
Series sunrpc: avoid -Wformat-security warning | expand

Commit Message

Arnd Bergmann July 19, 2024, 10:54 a.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

Using a non-constant string as an sprintf-style is potentially dangerous:

net/sunrpc/svc.c: In function 'param_get_pool_mode':
net/sunrpc/svc.c:164:32: error: format not a string literal and no format arguments [-Werror=format-security]

Use a literal "%s" format instead.

Fixes: 5f71f3c32553 ("sunrpc: refactor pool_mode setting code")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/sunrpc/svc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jeff Layton July 19, 2024, 11:57 a.m. UTC | #1
On Fri, 2024-07-19 at 12:54 +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Using a non-constant string as an sprintf-style is potentially dangerous:
> 
> net/sunrpc/svc.c: In function 'param_get_pool_mode':
> net/sunrpc/svc.c:164:32: error: format not a string literal and no format arguments [-Werror=format-security]
> 
> Use a literal "%s" format instead.
> 
> Fixes: 5f71f3c32553 ("sunrpc: refactor pool_mode setting code")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  net/sunrpc/svc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
> index e03f14024e47..88a59cfa5583 100644
> --- a/net/sunrpc/svc.c
> +++ b/net/sunrpc/svc.c
> @@ -161,7 +161,7 @@ param_get_pool_mode(char *buf, const struct kernel_param *kp)
>  	str[len] = '\n';
>  	str[len + 1] = '\0';
>  
> -	return sysfs_emit(buf, str);
> +	return sysfs_emit(buf, "%s", str);
>  }
>  
>  module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Chuck Lever III July 19, 2024, 2:08 p.m. UTC | #2
On Fri, Jul 19, 2024 at 12:54:22PM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Using a non-constant string as an sprintf-style is potentially dangerous:
> 
> net/sunrpc/svc.c: In function 'param_get_pool_mode':
> net/sunrpc/svc.c:164:32: error: format not a string literal and no format arguments [-Werror=format-security]
> 
> Use a literal "%s" format instead.
> 
> Fixes: 5f71f3c32553 ("sunrpc: refactor pool_mode setting code")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  net/sunrpc/svc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
> index e03f14024e47..88a59cfa5583 100644
> --- a/net/sunrpc/svc.c
> +++ b/net/sunrpc/svc.c
> @@ -161,7 +161,7 @@ param_get_pool_mode(char *buf, const struct kernel_param *kp)
>  	str[len] = '\n';
>  	str[len + 1] = '\0';
>  
> -	return sysfs_emit(buf, str);
> +	return sysfs_emit(buf, "%s", str);
>  }
>  
>  module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,
> -- 
> 2.39.2
> 

Applied to nfsd-fixes (for v6.11-rc). Thanks!
diff mbox series

Patch

diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index e03f14024e47..88a59cfa5583 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -161,7 +161,7 @@  param_get_pool_mode(char *buf, const struct kernel_param *kp)
 	str[len] = '\n';
 	str[len + 1] = '\0';
 
-	return sysfs_emit(buf, str);
+	return sysfs_emit(buf, "%s", str);
 }
 
 module_param_call(pool_mode, param_set_pool_mode, param_get_pool_mode,