diff mbox series

[V2] swuforward: fix segmentation fault after changing dictionary

Message ID 1516906628-20335-1-git-send-email-sbabic@denx.de
State Accepted
Headers show
Series [V2] swuforward: fix segmentation fault after changing dictionary | expand

Commit Message

Stefano Babic Jan. 25, 2018, 6:57 p.m. UTC
Recent commit d406032411bbced04e425f3a11c7f7f259443de0 changed the way
to use dictionary. The function dict_get_list() returns a list if
properties is found and the returned pointer must be checked before using it.

Missing check causes a segfault in swuforward when URLs are not parsed.

Signed-off-by: Stefano Babic <sbabic@denx.de>
Reported-by: Alexandre April <aapril@kinova.ca>
---

Changes since V1:
	- use a variable to store the list returned by dict_get_list()

 handlers/swuforward_handler.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Stefan Herbrechtsmeier Jan. 25, 2018, 7:07 p.m. UTC | #1
Hi Stefano,

Am 25.01.2018 um 19:57 schrieb Stefano Babic:
> Recent commit d406032411bbced04e425f3a11c7f7f259443de0 changed the way
> to use dictionary. The function dict_get_list() returns a list if
> properties is found and the returned pointer must be checked before using it.
>
> Missing check causes a segfault in swuforward when URLs are not parsed.
>
> Signed-off-by: Stefano Babic <sbabic@denx.de>
> Reported-by: Alexandre April <aapril@kinova.ca>
> ---
>
> Changes since V1:
> 	- use a variable to store the list returned by dict_get_list()
>
>   handlers/swuforward_handler.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c
> index 8b0c17f..8f2c133 100644
> --- a/handlers/swuforward_handler.c
> +++ b/handlers/swuforward_handler.c
> @@ -295,6 +295,7 @@ static int install_remote_swu(struct img_type *img,
>   	struct dict_list_elem *url;
>   	struct curl_slist *headerlist;
>   	CURLMsg *msg = NULL;
> +	struct dict_list *urls;
>   
>   	/*
>   	 * A single SWU can contains encrypted artifacts,
> @@ -307,6 +308,16 @@ static int install_remote_swu(struct img_type *img,
>   		return -EINVAL;
>   	}
>   
> +	/*
> +	 * Check if there is a list of URLs where to forward
> +	 * the SWU
> +	 */
> +	urls = dict_get_list(&img->properties, "url");
> +	if (!urls) {
> +		ERROR("SWU to be forwarded, but not remote URLs found ");
> +		return -EINVAL;
> +	}
> +
>   	/* Reset list of connections */
>   	LIST_INIT(&priv.conns);
>   
> @@ -320,7 +331,7 @@ static int install_remote_swu(struct img_type *img,
>   	priv.maxwaitms = MAX_WAIT_MS;
>   	priv.size = img->size;
>   
> -	LIST_FOREACH(url, dict_get_list(&img->properties, "url"), next) {
> +	LIST_FOREACH(url, urls, next) {
>   		char curlheader[SWUPDATE_GENERAL_STRING_SIZE + strlen(CUSTOM_HEADER)];
>   
>   		conn = (struct curlconn *)calloc(1, sizeof(struct curlconn));

Acked-by: Stefan Herbrechtsmeier <stefan@herbrechtsmeier.net>

Best regards
   Stefan
diff mbox series

Patch

diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c
index 8b0c17f..8f2c133 100644
--- a/handlers/swuforward_handler.c
+++ b/handlers/swuforward_handler.c
@@ -295,6 +295,7 @@  static int install_remote_swu(struct img_type *img,
 	struct dict_list_elem *url;
 	struct curl_slist *headerlist;
 	CURLMsg *msg = NULL;
+	struct dict_list *urls;
 
 	/*
 	 * A single SWU can contains encrypted artifacts,
@@ -307,6 +308,16 @@  static int install_remote_swu(struct img_type *img,
 		return -EINVAL;
 	}
 
+	/*
+	 * Check if there is a list of URLs where to forward
+	 * the SWU
+	 */
+	urls = dict_get_list(&img->properties, "url");
+	if (!urls) {
+		ERROR("SWU to be forwarded, but not remote URLs found ");
+		return -EINVAL;
+	}
+
 	/* Reset list of connections */
 	LIST_INIT(&priv.conns);
 
@@ -320,7 +331,7 @@  static int install_remote_swu(struct img_type *img,
 	priv.maxwaitms = MAX_WAIT_MS;
 	priv.size = img->size;
 
-	LIST_FOREACH(url, dict_get_list(&img->properties, "url"), next) {
+	LIST_FOREACH(url, urls, next) {
 		char curlheader[SWUPDATE_GENERAL_STRING_SIZE + strlen(CUSTOM_HEADER)];
 
 		conn = (struct curlconn *)calloc(1, sizeof(struct curlconn));