diff mbox series

archive handler: check return value from newlocale()

Message ID 20240202172330.1788738-1-marcus.folkesson@gmail.com
State Accepted
Headers show
Series archive handler: check return value from newlocale() | expand

Commit Message

Marcus Folkesson Feb. 2, 2024, 5:23 p.m. UTC
In case that the system does not support locales, swupdate will end up
with a segmentation fault upon freelocale().

Do not consider this to be critical, IOW proceed with the installation
but inform the user by an error in the log.

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
 handlers/archive_handler.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Stefano Babic Feb. 2, 2024, 6:25 p.m. UTC | #1
On 02.02.24 18:23, Marcus Folkesson wrote:
> In case that the system does not support locales, swupdate will end up
> with a segmentation fault upon freelocale().
>
> Do not consider this to be critical, IOW proceed with the installation
> but inform the user by an error in the log.
>
> Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
> ---
>   handlers/archive_handler.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/handlers/archive_handler.c b/handlers/archive_handler.c
> index c19e991..f973a27 100644
> --- a/handlers/archive_handler.c
> +++ b/handlers/archive_handler.c
> @@ -107,7 +107,11 @@ extract(void *p)
>   	 *  https://github.com/libarchive/libarchive/wiki/Filenames
>   	 */
>   	archive_locale = newlocale(LC_CTYPE_MASK, "", (locale_t)0);
> -	old_locale = uselocale(archive_locale);
> +	if (archive_locale == 0) {
> +		ERROR("newlocale(): %s", strerror(errno));
> +	} else {
> +		old_locale = uselocale(archive_locale);
> +	}
>   #endif
>
>   	a = archive_read_new();
> @@ -210,8 +214,10 @@ out:
>   	free(FIFO);
>
>   #ifdef CONFIG_LOCALE
> -	uselocale(old_locale);
> -	freelocale(archive_locale);
> +	if (archive_locale != 0) {
> +		uselocale(old_locale);
> +		freelocale(archive_locale);
> +	}
>   #endif
>   	data->exitval = exitval;
>   	pthread_exit(NULL);

Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/handlers/archive_handler.c b/handlers/archive_handler.c
index c19e991..f973a27 100644
--- a/handlers/archive_handler.c
+++ b/handlers/archive_handler.c
@@ -107,7 +107,11 @@  extract(void *p)
 	 *  https://github.com/libarchive/libarchive/wiki/Filenames
 	 */
 	archive_locale = newlocale(LC_CTYPE_MASK, "", (locale_t)0);
-	old_locale = uselocale(archive_locale);
+	if (archive_locale == 0) {
+		ERROR("newlocale(): %s", strerror(errno));
+	} else {
+		old_locale = uselocale(archive_locale);
+	}
 #endif
 
 	a = archive_read_new();
@@ -210,8 +214,10 @@  out:
 	free(FIFO);
 
 #ifdef CONFIG_LOCALE
-	uselocale(old_locale);
-	freelocale(archive_locale);
+	if (archive_locale != 0) {
+		uselocale(old_locale);
+		freelocale(archive_locale);
+	}
 #endif
 	data->exitval = exitval;
 	pthread_exit(NULL);