@@ -2751,7 +2751,7 @@ xrdp_mm_get_sesman_port(char *port, int port_bytes)
2751
2751
2752
2752
g_memset (cfg_file , 0 , sizeof (char ) * 256 );
2753
2753
/* default to port 3350 */
2754
- g_strncpy (port , "3350" , port_bytes - 1 );
2754
+ strlcpy (port , "3350" , port_bytes );
2755
2755
/* see if port is in sesman.ini file */
2756
2756
g_snprintf (cfg_file , 255 , "%s/sesman.ini" , XRDP_CFG_PATH );
2757
2757
fd = g_file_open_ro (cfg_file );
@@ -2778,7 +2778,7 @@ xrdp_mm_get_sesman_port(char *port, int port_bytes)
2778
2778
2779
2779
if ((error > 0 ) && (error < 65000 ))
2780
2780
{
2781
- g_strncpy (port , val , port_bytes - 1 );
2781
+ strlcpy (port , val , port_bytes );
2782
2782
}
2783
2783
2784
2784
break ;
@@ -3048,7 +3048,13 @@ parse_chansrvport(const char *value, char *dest, int dest_size, int uid)
3048
3048
int rv = 0 ;
3049
3049
int dnum = 0 ;
3050
3050
3051
- if (g_strncmp (value , "DISPLAY(" , 8 ) == 0 )
3051
+ if (value == NULL )
3052
+ {
3053
+ LOG (LOG_LEVEL_WARNING ,
3054
+ "unexpectedly empty chansrvport string encountered" );
3055
+ rv = -1 ;
3056
+ }
3057
+ else if (g_strncmp (value , "DISPLAY(" , 8 ) == 0 )
3052
3058
{
3053
3059
const char * p = value + 8 ;
3054
3060
const char * end = p ;
@@ -3103,7 +3109,7 @@ parse_chansrvport(const char *value, char *dest, int dest_size, int uid)
3103
3109
}
3104
3110
else
3105
3111
{
3106
- g_strncpy (dest , value , dest_size - 1 );
3112
+ strlcpy (dest , value , dest_size );
3107
3113
}
3108
3114
3109
3115
return rv ;
@@ -3354,11 +3360,16 @@ xrdp_mm_connect_sm(struct xrdp_mm *self)
3354
3360
3355
3361
gw_username = xrdp_mm_get_value (self , "pamusername" );
3356
3362
gw_password = xrdp_mm_get_value (self , "pampassword" );
3357
- if (!g_strcmp (gw_username , "same" ))
3363
+ // gw_username shouldn't be NULL here, but we'll
3364
+ // check it anyway before dereferencing.
3365
+ if (gw_username != NULL &&
3366
+ !g_strcmp (gw_username , "same" ))
3358
3367
{
3359
3368
gw_username = xrdp_mm_get_value (self , "username" );
3360
3369
}
3361
3370
3371
+ // Default the password to the usual one if the
3372
+ // user hasn't specified one, or specified 'same'
3362
3373
if (gw_password == NULL ||
3363
3374
!g_strcmp (gw_password , "same" ))
3364
3375
{
@@ -3475,7 +3486,6 @@ xrdp_mm_connect_sm(struct xrdp_mm *self)
3475
3486
if (self -> use_chansrv )
3476
3487
{
3477
3488
char portbuff [XRDP_SOCKETS_MAXPATH ];
3478
-
3479
3489
if (self -> use_sesman )
3480
3490
{
3481
3491
g_snprintf (portbuff , sizeof (portbuff ),
@@ -3486,16 +3496,25 @@ xrdp_mm_connect_sm(struct xrdp_mm *self)
3486
3496
else
3487
3497
{
3488
3498
const char * cp = xrdp_mm_get_value (self , "chansrvport" );
3489
- portbuff [0 ] = '\0' ;
3490
- parse_chansrvport (cp , portbuff , sizeof (portbuff ),
3491
- self -> uid );
3499
+ if (parse_chansrvport (cp , portbuff , sizeof (portbuff ),
3500
+ self -> uid ) == 0 )
3501
+ {
3502
+ xrdp_wm_log_msg (self -> wm , LOG_LEVEL_INFO ,
3503
+ "Connecting to chansrv on %s" ,
3504
+ portbuff );
3505
+ }
3506
+ else
3507
+ {
3508
+ // An error has already been logged
3509
+ portbuff [0 ] = '\0' ;
3510
+ }
3511
+ }
3492
3512
3493
- xrdp_wm_log_msg (self -> wm , LOG_LEVEL_INFO ,
3494
- "Connecting to chansrv on %s" ,
3495
- portbuff );
3513
+ if (portbuff [0 ] != '\0' )
3514
+ {
3515
+ xrdp_mm_update_allowed_channels (self );
3516
+ xrdp_mm_chansrv_connect (self , portbuff );
3496
3517
}
3497
- xrdp_mm_update_allowed_channels (self );
3498
- xrdp_mm_chansrv_connect (self , portbuff );
3499
3518
}
3500
3519
}
3501
3520
break ;
0 commit comments