diff mbox series

[v2] Lua: Null check return value of luaL_checkstring functions

Message ID 1517239175-18678-1-git-send-email-stefan@herbrechtsmeier.net
State Accepted
Headers show
Series [v2] Lua: Null check return value of luaL_checkstring functions | expand

Commit Message

Stefan Herbrechtsmeier Jan. 29, 2018, 3:19 p.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

---

Changes in v2:
- Correct null check of name variable inside l_get_bootenv and l_set_bootenv function

 corelib/lua_interface.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Stefano Babic Jan. 29, 2018, 6:38 p.m. UTC | #1
On 29/01/2018 16:19, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> ---
> 
> Changes in v2:
> - Correct null check of name variable inside l_get_bootenv and l_set_bootenv function
> 
>  corelib/lua_interface.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index 78c4df4..ed0849a 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -614,7 +614,7 @@ static int l_notify (lua_State *L) {
>  	lua_Number error  =  luaL_checknumber (L, 2);
>  	const char *msg   =  luaL_checkstring (L, 3);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		notify((RECOVERY_STATUS)status, (int)error, INFOLEVEL, msg);
>  
>  	lua_pop(L, 3);
> @@ -624,7 +624,7 @@ static int l_notify (lua_State *L) {
>  static int l_trace(lua_State *L) {
>  	const char *msg = luaL_checkstring (L, 1);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		TRACE("%s", msg);
>  
>  	lua_pop(L, 1);
> @@ -634,7 +634,7 @@ static int l_trace(lua_State *L) {
>  static int l_error(lua_State *L) {
>  	const char *msg = luaL_checkstring (L, 1);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		ERROR("%s", msg);
>  
>  	lua_pop(L, 1);
> @@ -644,7 +644,7 @@ static int l_error(lua_State *L) {
>  static int l_info(lua_State *L) {
>  	const char *msg = luaL_checkstring (L, 1);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		INFO("%s", msg);
>  
>  	lua_pop(L, 1);
> @@ -721,7 +721,7 @@ static int l_get_bootenv(lua_State *L) {
>  	const char *name = luaL_checkstring(L, 1);
>  	char *value = NULL;
>  
> -	if (strlen(name))
> +	if (name && strlen(name))
>  		value = bootloader_env_get(name);
>  	lua_pop(L, 1);
>  
> @@ -736,8 +736,8 @@ static int l_set_bootenv(lua_State *L) {
>  	const char *name = luaL_checkstring(L, 1);
>  	const char *value = luaL_checkstring(L, 2);
>  
> -	if (strlen(name))
> -		dict_set_value(bootenv, name, value);
> +	if (name && strlen(name))
> +		dict_set_value(bootenv, name, value ? value : "");
>  	lua_pop(L, 2);
>  
>  	return 0;
> 

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

Best regards,
Stefano Babic
Stefano Babic Jan. 30, 2018, 12:07 p.m. UTC | #2
On 29/01/2018 16:19, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> ---
> 
> Changes in v2:
> - Correct null check of name variable inside l_get_bootenv and l_set_bootenv function
> 
>  corelib/lua_interface.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
> index 78c4df4..ed0849a 100644
> --- a/corelib/lua_interface.c
> +++ b/corelib/lua_interface.c
> @@ -614,7 +614,7 @@ static int l_notify (lua_State *L) {
>  	lua_Number error  =  luaL_checknumber (L, 2);
>  	const char *msg   =  luaL_checkstring (L, 3);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		notify((RECOVERY_STATUS)status, (int)error, INFOLEVEL, msg);
>  
>  	lua_pop(L, 3);
> @@ -624,7 +624,7 @@ static int l_notify (lua_State *L) {
>  static int l_trace(lua_State *L) {
>  	const char *msg = luaL_checkstring (L, 1);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		TRACE("%s", msg);
>  
>  	lua_pop(L, 1);
> @@ -634,7 +634,7 @@ static int l_trace(lua_State *L) {
>  static int l_error(lua_State *L) {
>  	const char *msg = luaL_checkstring (L, 1);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		ERROR("%s", msg);
>  
>  	lua_pop(L, 1);
> @@ -644,7 +644,7 @@ static int l_error(lua_State *L) {
>  static int l_info(lua_State *L) {
>  	const char *msg = luaL_checkstring (L, 1);
>  
> -	if (strlen(msg))
> +	if (msg && strlen(msg))
>  		INFO("%s", msg);
>  
>  	lua_pop(L, 1);
> @@ -721,7 +721,7 @@ static int l_get_bootenv(lua_State *L) {
>  	const char *name = luaL_checkstring(L, 1);
>  	char *value = NULL;
>  
> -	if (strlen(name))
> +	if (name && strlen(name))
>  		value = bootloader_env_get(name);
>  	lua_pop(L, 1);
>  
> @@ -736,8 +736,8 @@ static int l_set_bootenv(lua_State *L) {
>  	const char *name = luaL_checkstring(L, 1);
>  	const char *value = luaL_checkstring(L, 2);
>  
> -	if (strlen(name))
> -		dict_set_value(bootenv, name, value);
> +	if (name && strlen(name))
> +		dict_set_value(bootenv, name, value ? value : "");
>  	lua_pop(L, 2);
>  
>  	return 0;
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 78c4df4..ed0849a 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -614,7 +614,7 @@  static int l_notify (lua_State *L) {
 	lua_Number error  =  luaL_checknumber (L, 2);
 	const char *msg   =  luaL_checkstring (L, 3);
 
-	if (strlen(msg))
+	if (msg && strlen(msg))
 		notify((RECOVERY_STATUS)status, (int)error, INFOLEVEL, msg);
 
 	lua_pop(L, 3);
@@ -624,7 +624,7 @@  static int l_notify (lua_State *L) {
 static int l_trace(lua_State *L) {
 	const char *msg = luaL_checkstring (L, 1);
 
-	if (strlen(msg))
+	if (msg && strlen(msg))
 		TRACE("%s", msg);
 
 	lua_pop(L, 1);
@@ -634,7 +634,7 @@  static int l_trace(lua_State *L) {
 static int l_error(lua_State *L) {
 	const char *msg = luaL_checkstring (L, 1);
 
-	if (strlen(msg))
+	if (msg && strlen(msg))
 		ERROR("%s", msg);
 
 	lua_pop(L, 1);
@@ -644,7 +644,7 @@  static int l_error(lua_State *L) {
 static int l_info(lua_State *L) {
 	const char *msg = luaL_checkstring (L, 1);
 
-	if (strlen(msg))
+	if (msg && strlen(msg))
 		INFO("%s", msg);
 
 	lua_pop(L, 1);
@@ -721,7 +721,7 @@  static int l_get_bootenv(lua_State *L) {
 	const char *name = luaL_checkstring(L, 1);
 	char *value = NULL;
 
-	if (strlen(name))
+	if (name && strlen(name))
 		value = bootloader_env_get(name);
 	lua_pop(L, 1);
 
@@ -736,8 +736,8 @@  static int l_set_bootenv(lua_State *L) {
 	const char *name = luaL_checkstring(L, 1);
 	const char *value = luaL_checkstring(L, 2);
 
-	if (strlen(name))
-		dict_set_value(bootenv, name, value);
+	if (name && strlen(name))
+		dict_set_value(bootenv, name, value ? value : "");
 	lua_pop(L, 2);
 
 	return 0;