Show
Ignore:
Timestamp:
2008-07-02 02:19:14 (5 months ago)
Author:
Rocco Rutte <pdmef@…>
Branch:
HEAD
Message:

Use realpath() in mutt_pretty_mailbox() for paths that may need it.
This requires to add the buffer size as parameter since the result may
be longer than the original but still fit in the buffer. Closes #2948.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • muttlib.c

    r5365 r5443  
    754754 
    755755/* collapse the pathname using ~ or = when possible */ 
    756 void mutt_pretty_mailbox (char *s) 
     756void mutt_pretty_mailbox (char *s, size_t buflen) 
    757757{ 
    758758  char *p = s, *q = s; 
    759759  size_t len; 
    760760  url_scheme_t scheme; 
     761  char tmp[_POSIX_PATH_MAX]; 
    761762 
    762763  scheme = url_check_scheme (s); 
     
    780781    p = q; 
    781782  } 
    782    
    783   /* first attempt to collapse the pathname */ 
    784   while (*p) 
    785   { 
    786     if (*p == '/' && p[1] == '/') 
    787     { 
    788       *q++ = '/'; 
    789       p += 2; 
    790     } 
    791     else if (p[0] == '/' && p[1] == '.' && p[2] == '/') 
    792     { 
    793       *q++ = '/'; 
    794       p += 3; 
    795     } 
    796     else 
    797       *q++ = *p++; 
    798   } 
    799   *q = 0; 
     783 
     784  /* cleanup path */ 
     785  if (strstr (p, "//") || strstr (p, "/./")) 
     786  { 
     787    /* first attempt to collapse the pathname, this is more 
     788     * lightweight than realpath() and doesn't resolve links 
     789     */ 
     790    while (*p) 
     791    { 
     792      if (*p == '/' && p[1] == '/') 
     793      { 
     794        *q++ = '/'; 
     795        p += 2; 
     796      } 
     797      else if (p[0] == '/' && p[1] == '.' && p[2] == '/') 
     798      { 
     799        *q++ = '/'; 
     800        p += 3; 
     801      } 
     802      else 
     803        *q++ = *p++; 
     804    } 
     805    *q = 0; 
     806  } 
     807  else if (strstr (p, "..") &&  
     808           (scheme == U_UNKNOWN || scheme == U_FILE) && 
     809           realpath (p, tmp)) 
     810    strfcpy (p, tmp, buflen - (p - s)); 
    800811 
    801812  if (mutt_strncmp (s, Maildir, (len = mutt_strlen (Maildir))) == 0 &&