diff mbox series

Extend maximal length of command line arguments

Message ID 20190425072340.32346-1-lukasz.laguna@3mdeb.com
State Changes Requested
Headers show
Series Extend maximal length of command line arguments | expand

Commit Message

Łukasz Łaguna April 25, 2019, 7:23 a.m. UTC
Hi,
We had a problem when trying to download SWU packages from long URLs. Size of allocated memory for cmdline is hardcoded to 1024 bytes, so when links have more characters they get cut off. We prepared patch resolving this issue, but applying it with every meta-swupdate update is problematic. The patch below may not be the best solution, but can serve as an example. Could you please help us with defining the best solution, which could be used in mainline? We would be very happy if we could implement it.

Signed-off-by: Łukasz Łaguna <lukasz.laguna@3mdeb.com>
---
 core/swupdate.c   | 6 +++---
 include/globals.h | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Stefano Babic April 25, 2019, 4:19 p.m. UTC | #1
Hi Łukasz,

On 25/04/19 09:23, Łukasz Łaguna wrote:
> Hi,
> We had a problem when trying to download SWU packages from long URLs. Size of allocated memory for cmdline is hardcoded to 1024 bytes, so when links have more characters they get cut off.

well, as the 1KB size is for each subsystem (downloader/suricatta/...),
this URL is HUGE.

> We prepared patch resolving this issue, but applying it with every meta-swupdate update is problematic. The patch below may not be the best solution, but can serve as an example. Could you please help us with defining the best solution, which could be used in mainline? We would be very happy if we could implement it.

This just moves out the problem - as I understand that it is impossible
to know how users set the links and to provide a fixed size, this must
be done dynamically. We need to switch to alloca() / asprintf(), where
the string is copied and allocated on the heap. Of course, the memory
must be freed later after usage.


See also:

commit e4756a67336b48150c576adda1c8faca5cfb9294
Author: Stefano Babic <sbabic@denx.de>
Date:   Mon Nov 5 16:08:19 2018 +0100

    installer: allow filenames longer as 64 chars

    Signed-off-by: Stefano Babic <sbabic@denx.de>

to get some ideas.

Best regards,
Stefano Babic

> 
> Signed-off-by: Łukasz Łaguna <lukasz.laguna@3mdeb.com>
> ---
>  core/swupdate.c   | 6 +++---
>  include/globals.h | 1 +
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/core/swupdate.c b/core/swupdate.c
> index febf12acc9a7..d27dce341fd6 100644
> --- a/core/swupdate.c
> +++ b/core/swupdate.c
> @@ -586,19 +586,19 @@ int main(int argc, char **argv)
>  	int result = EXIT_SUCCESS;
>  #ifdef CONFIG_SURICATTA
>  	int opt_u = 0;
> -	char suricattaoptions[1024];
> +	char suricattaoptions[MAX_COMMAND_LINE];
>  	char **argvalues = NULL;
>  	int argcount = 0;
>  #endif
>  #ifdef CONFIG_WEBSERVER
>  	int opt_w = 0;
> -	char weboptions[1024];
> +	char weboptions[MAX_COMMAND_LINE];
>  	char **av = NULL;
>  	int ac = 0;
>  #endif
>  #ifdef CONFIG_DOWNLOAD
>  	int opt_d = 0;
> -	char dwloptions[1024];
> +	char dwloptions[MAX_COMMAND_LINE];
>  #endif
>  	char **dwlav = NULL;
>  	int dwlac = 0;
> diff --git a/include/globals.h b/include/globals.h
> index f797f4f4e37b..21926e6ea662 100644
> --- a/include/globals.h
> +++ b/include/globals.h
> @@ -21,6 +21,7 @@
>  #define MAX_REVISION_LENGTH	SWUPDATE_GENERAL_STRING_SIZE
>  #define MAX_BOOT_SCRIPT_LINE_LENGTH	1024
>  #define MAX_SEEK_STRING_SIZE	32
> +#define MAX_COMMAND_LINE 2048
>  
>  /* These are fixed path to temporary files */
>  #define SCRIPTS_DIR_SUFFIX	"scripts/"
>
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index febf12acc9a7..d27dce341fd6 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -586,19 +586,19 @@  int main(int argc, char **argv)
 	int result = EXIT_SUCCESS;
 #ifdef CONFIG_SURICATTA
 	int opt_u = 0;
-	char suricattaoptions[1024];
+	char suricattaoptions[MAX_COMMAND_LINE];
 	char **argvalues = NULL;
 	int argcount = 0;
 #endif
 #ifdef CONFIG_WEBSERVER
 	int opt_w = 0;
-	char weboptions[1024];
+	char weboptions[MAX_COMMAND_LINE];
 	char **av = NULL;
 	int ac = 0;
 #endif
 #ifdef CONFIG_DOWNLOAD
 	int opt_d = 0;
-	char dwloptions[1024];
+	char dwloptions[MAX_COMMAND_LINE];
 #endif
 	char **dwlav = NULL;
 	int dwlac = 0;
diff --git a/include/globals.h b/include/globals.h
index f797f4f4e37b..21926e6ea662 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -21,6 +21,7 @@ 
 #define MAX_REVISION_LENGTH	SWUPDATE_GENERAL_STRING_SIZE
 #define MAX_BOOT_SCRIPT_LINE_LENGTH	1024
 #define MAX_SEEK_STRING_SIZE	32
+#define MAX_COMMAND_LINE 2048
 
 /* These are fixed path to temporary files */
 #define SCRIPTS_DIR_SUFFIX	"scripts/"