[vlc-devel] [PATCH] bdsm: Check for asprintf return value instead of out pointer value

Julien 'Lta' BALLET elthariel at gmail.com
Mon Jun 30 17:09:07 CEST 2014


From: Julien 'Lta' BALLET <contact at lta.io>

---
 modules/access/bdsm/access.c  |  5 +++--
 modules/access/bdsm/browser.c | 20 +++++++++++---------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/modules/access/bdsm/access.c b/modules/access/bdsm/access.c
index 4cbbe90..fd7999c 100644
--- a/modules/access/bdsm/access.c
+++ b/modules/access/bdsm/access.c
@@ -281,9 +281,10 @@ static bool get_address( access_t *p_access, access_sys_t *p_sys )
 static void login_dialog( access_t *p_access, access_sys_t *p_sys )
 {
     char *psz_login = NULL, *psz_pass = NULL, *psz_title;
+    int i_ret;
 
-    asprintf( &psz_title, BDSM_LOGIN_DIALOG_TITLE, p_sys->netbios_name );
-    if( psz_title != NULL )
+    i_ret = asprintf( &psz_title, BDSM_LOGIN_DIALOG_TITLE, p_sys->netbios_name );
+    if( i_ret != -1 )
         dialog_Login( p_access, &psz_login, &psz_pass, psz_title,
                       BDSM_LOGIN_DIALOG_TEXT );
     else
diff --git a/modules/access/bdsm/browser.c b/modules/access/bdsm/browser.c
index a69936f..1c6a959 100644
--- a/modules/access/bdsm/browser.c
+++ b/modules/access/bdsm/browser.c
@@ -84,11 +84,12 @@ static int BrowseDirectory( access_t *p_access, input_item_node_t *p_node )
     smb_stat        st;
     const char     *psz_query, *psz_name;
     size_t          files_count;
+    int             i_ret;
 
     if( p_sys->psz_path != NULL )
     {
-        asprintf( &psz_query, "%s\\*", p_sys->psz_path );
-        if( psz_query == NULL )
+        i_ret = asprintf( &psz_query, "%s\\*", p_sys->psz_path );
+        if( i_ret == -1 )
             return VLC_ENOMEM;
         files = smb_find( p_sys->p_session, p_sys->i_tid, psz_query );
         free( psz_query );
@@ -159,10 +160,11 @@ static bool AddToNode( access_t *p_access, input_item_node_t *p_node,
     access_sys_t *p_sys = p_access->p_sys;
     input_item_t *p_item;
     char         *psz_uri, *psz_option;
+    int           i_ret;
 
-    asprintf( &psz_uri, "%s/%s", p_node->p_item->psz_uri, psz_name );
+    i_ret = asprintf( &psz_uri, "%s/%s", p_node->p_item->psz_uri, psz_name );
     /* XXX Handle ENOMEM by enabling retry */
-    if( psz_uri == NULL )
+    if( i_ret == -1 )
         return false;
 
     p_item = input_item_New( psz_uri, psz_name );
@@ -175,16 +177,16 @@ static bool AddToNode( access_t *p_access, input_item_node_t *p_node,
 
     /* Here we save on the node the credentials that allowed us to login.
      * That way the user isn't prompted more than once for credentials */
-    asprintf( &psz_option, "smb-user=%s", p_sys->creds.login );
-    if( psz_option != NULL )
+    i_ret = asprintf( &psz_option, "smb-user=%s", p_sys->creds.login );
+    if( i_ret != -1 )
         input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
     free( psz_option );
-    asprintf( &psz_option, "smb-pwd=%s", p_sys->creds.password );
-    if( psz_option != NULL )
+    i_ret = asprintf( &psz_option, "smb-pwd=%s", p_sys->creds.password );
+    if( i_ret == -1 )
         input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
     free( psz_option );
     asprintf( &psz_option, "smb-domain=%s", p_sys->creds.domain );
-    if( psz_option != NULL )
+    if( i_ret == -1 )
         input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
     free( psz_option );
 
-- 
2.0.0




More information about the vlc-devel mailing list