diff mbox series

Lua: fix segfault in image property handling

Message ID 20190521124551.3484-1-christian.storm@siemens.com
State Accepted
Headers show
Series Lua: fix segfault in image property handling | expand

Commit Message

Storm, Christian May 21, 2019, 12:45 p.m. UTC
table2image() calls lua_dump_table() with the 'key' parameter being
NULL and the 'img' parameter set. Subsequently, dict_insert_value() is
called with key == NULL if the Lua stack key's type is string or number,
segfaulting SWUpdate.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
Reported-by: Akihiro Suzuki <akihiro27.suzuki@toshiba.co.jp>
---
 corelib/lua_interface.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Stefano Babic May 22, 2019, 1:23 p.m. UTC | #1
On 21/05/19 14:45, Christian Storm wrote:
> table2image() calls lua_dump_table() with the 'key' parameter being
> NULL and the 'img' parameter set. Subsequently, dict_insert_value() is
> called with key == NULL if the Lua stack key's type is string or number,
> segfaulting SWUpdate.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> Reported-by: Akihiro Suzuki <akihiro27.suzuki@toshiba.co.jp>
> ---
>  corelib/lua_interface.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index d4ebe4a..443f149 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -80,11 +80,11 @@ static void lua_dump_table(lua_State *L, char *str, struct img_type *img, const
>  					lua_tostring(L, -1),
>  					lua_tostring(L, -2));
>  				if (img) {
> -					TRACE("Inserting property %s[%s] = %s",
> -							key,
> -							lua_tostring(L, -1),
> +					TRACE("Inserting property %s = %s",
> +							key ? key : lua_tostring(L, -1),
>  							lua_tostring(L, -2));
> -					dict_insert_value(&img->properties, key,
> +					dict_insert_value(&img->properties,
> +							key ? key : lua_tostring(L, -1),
>  							lua_tostring(L, -2));
>  				}
>  				break;
> 

Thanks for fixing this !

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

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index d4ebe4a..443f149 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -80,11 +80,11 @@  static void lua_dump_table(lua_State *L, char *str, struct img_type *img, const
 					lua_tostring(L, -1),
 					lua_tostring(L, -2));
 				if (img) {
-					TRACE("Inserting property %s[%s] = %s",
-							key,
-							lua_tostring(L, -1),
+					TRACE("Inserting property %s = %s",
+							key ? key : lua_tostring(L, -1),
 							lua_tostring(L, -2));
-					dict_insert_value(&img->properties, key,
+					dict_insert_value(&img->properties,
+							key ? key : lua_tostring(L, -1),
 							lua_tostring(L, -2));
 				}
 				break;