misc-progs: Add path to executable to argv

Message ID 20220615095320.1972533-1-michael.tremer@ipfire.org
State Accepted
Commit a609195a26f2666a177b988a6691bc27b10e6d64
Headers
Series misc-progs: Add path to executable to argv |

Commit Message

Michael Tremer June 15, 2022, 9:53 a.m. UTC
  Otherwise, the first argument would always be swollowed :(

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 src/misc-progs/setuid.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
  

Comments

Peter Müller June 17, 2022, 8:52 a.m. UTC | #1
Acked-by: Peter Müller <peter.mueller@ipfire.org>

> Otherwise, the first argument would always be swollowed :(
> 
> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
> ---
>   src/misc-progs/setuid.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/src/misc-progs/setuid.c b/src/misc-progs/setuid.c
> index 831fb1f90..17b0e7066 100644
> --- a/src/misc-progs/setuid.c
> +++ b/src/misc-progs/setuid.c
> @@ -61,10 +61,8 @@ static int system_core(char* command, char** args, uid_t uid, gid_t gid, char *e
>   	if(!command)
>   		return 1;
>   
> -#if 0
>   	// Add command as first element to argv
>   	argv[argc++] = command;
> -#endif
>   
>   	// Add all other arguments
>   	if (args) {
> @@ -138,7 +136,7 @@ int safe_system(char* command) {
>   		NULL,
>   	};
>   
> -	return system_core(argv[0], argv, 0, 0, "safe_system");
> +	return system_core(argv[0], argv + 1, 0, 0, "safe_system");
>   }
>   
>   /* Much like safe_system but lets you specify a non-root uid and gid to run
> @@ -151,7 +149,7 @@ int unpriv_system(char* command, uid_t uid, gid_t gid) {
>   		NULL,
>   	};
>   
> -	return system_core(argv[0], argv, uid, gid, "unpriv_system");
> +	return system_core(argv[0], argv + 1, uid, gid, "unpriv_system");
>   }
>   
>   /* General routine to initialise a setuid root program, and put the
  

Patch

diff --git a/src/misc-progs/setuid.c b/src/misc-progs/setuid.c
index 831fb1f90..17b0e7066 100644
--- a/src/misc-progs/setuid.c
+++ b/src/misc-progs/setuid.c
@@ -61,10 +61,8 @@  static int system_core(char* command, char** args, uid_t uid, gid_t gid, char *e
 	if(!command)
 		return 1;
 
-#if 0
 	// Add command as first element to argv
 	argv[argc++] = command;
-#endif
 
 	// Add all other arguments
 	if (args) {
@@ -138,7 +136,7 @@  int safe_system(char* command) {
 		NULL,
 	};
 
-	return system_core(argv[0], argv, 0, 0, "safe_system");
+	return system_core(argv[0], argv + 1, 0, 0, "safe_system");
 }
 
 /* Much like safe_system but lets you specify a non-root uid and gid to run
@@ -151,7 +149,7 @@  int unpriv_system(char* command, uid_t uid, gid_t gid) {
 		NULL,
 	};
 
-	return system_core(argv[0], argv, uid, gid, "unpriv_system");
+	return system_core(argv[0], argv + 1, uid, gid, "unpriv_system");
 }
 
 /* General routine to initialise a setuid root program, and put the