Changeset 5754:b23d79c13370 in roaraudio for libroarpulse/util.c


Ignore:
Timestamp:
11/16/12 16:49:56 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

avoid getenv() and use more portable roar_env_get(). Also improved security as we enfore const now on bufferes obtained from the env.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroarpulse/util.c

    r5381 r5754  
    7373/** Return the current username in the specified string buffer. */ 
    7474char *pa_get_user_name(char *s, size_t l) { 
    75  char * user = NULL; 
     75 const char * user = NULL; 
    7676 
    7777 if ( s == NULL ) { 
     
    8282 
    8383 if ( user == NULL ) 
    84   user = getenv("USER"); 
     84  user = roar_env_get("USER"); 
    8585 if ( user == NULL ) 
    86   user = getenv("LOGNAME"); 
     86  user = roar_env_get("LOGNAME"); 
    8787 if ( user == NULL ) 
    88   user = getenv("USERNAME"); 
     88  user = roar_env_get("USERNAME"); 
    8989 
    9090#ifdef ROAR_HAVE_GETUID 
     
    126126/** Return the home directory of the current user */ 
    127127char *pa_get_home_dir(char *s, size_t l) { 
    128  char * home = getenv("HOME"); 
    129  
    130  if ( home == NULL ) 
     128 if ( roar_env_render_path_r(s, l, "~/") == -1 ) 
    131129  return NULL; 
    132  
    133  strncpy(s, home, l); 
    134  
    135  s[l-1] = 0; 
    136130 
    137131 return s; 
Note: See TracChangeset for help on using the changeset viewer.