NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/47577: Mail(1)/mail(1)/mailx(1) gets stuck when current folder becomes accessible



The following reply was made to PR bin/47577; it has been noted by GNATS.

From: Steffen "Daode" Nurpmeso <sdaoden%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: bin/47577: Mail(1)/mail(1)/mailx(1) gets stuck when current
 folder becomes accessible
Date: Tue, 19 Feb 2013 18:26:49 +0100

 aaah, i get grazy, wrong lex.c.orig.
 
 --- fio.c.orig 2013-02-19 01:06:53.000000000 +0100
 +++ fio.c      2013-02-19 03:00:56.000000000 +0100
 @@ -392,14 +392,18 @@ fsize(FILE *iob)
  PUBLIC int
  getfold(char *name, size_t namesize)
  {
 +      char unres[PATHSIZE], res[PATHSIZE];
        char *folder;
 =20
        if ((folder =3D value(ENAME_FOLDER)) =3D=3D NULL)
                return -1;
        if (*folder =3D=3D '/')
 -              (void)strlcpy(name, folder, namesize);
 +              (void)strlcpy(unres, folder, sizeof unres);
        else
 -              (void)snprintf(name, namesize, "%s/%s", homedir, folder);
 +              (void)snprintf(unres, sizeof unres, "%s/%s", homedir, folder);
 +      if (realpath(unres, res) =3D=3D NULL)
 +              err(EXIT_FAILURE, "Can't canonicalize *folder* `%s'", unres);
 +      (void)strlcpy(name, res, namesize);
        return 0;
  }
 =20
 --- glob.h.orig        2013-02-18 17:39:46.000000000 +0100
 +++ glob.h     2013-02-19 03:02:37.000000000 +0100
 @@ -59,6 +59,7 @@ EXTERN FILE  *otf;                           /* Output temp 
file
  EXTERN int    image;                          /* File descriptor for image of 
msg */
  EXTERN FILE   *input;                         /* Current command input file */
  EXTERN char   mailname[PATHSIZE];             /* Name of current file */
 +EXTERN char   displayname[80];                /* Prettyfied for display */
  EXTERN char   prevfile[PATHSIZE];             /* Name of previous file */
  EXTERN char   *tmpdir;                        /* Path name of temp directory 
*/
  EXTERN char   *homedir;                       /* Path name of home directory 
*/
 --- lex.c.orig 2013-02-19 03:23:22.000000000 +0100
 +++ lex.c      2013-02-19 03:05:58.000000000 +0100
 @@ -141,6 +141,45 @@ file_leak_check(void)
  }
  #endif /* DEBUG_FILE_LEAK */
 =20
 +static void
 +_update_mailname(char const *name)
 +{
 +      char tbuf[PATHSIZE];
 +      size_t l;
 +
 +      if (realpath(name, mailname) =3D=3D NULL)
 +              err(EXIT_FAILURE, "Can't canonicalize `%s'", name);
 +
 +      if (getfold(tbuf, sizeof tbuf) >=3D 0) {
 +              l =3D strlen(tbuf);
 +              if (l < sizeof(tbuf) - 1)
 +                      tbuf[l++] =3D '/';
 +              if (strncmp(tbuf, mailname, l) =3D=3D 0) {
 +                      char const *sep =3D "", *cp =3D mailname + l;
 +
 +                      l =3D strlen(cp);
 +                      if (l >=3D sizeof displayname) {
 +                              cp +=3D l;
 +                              cp -=3D sizeof(displayname) - 5;
 +                              sep =3D "...";
 +                      }
 +                      (void)snprintf(displayname, sizeof displayname,
 +                              "+%s%s", sep, cp);
 +                      goto jleave;
 +              }
 +      }
 +
 +      l =3D strlen(mailname);
 +      if (l < sizeof displayname)
 +              strcpy(displayname, mailname);
 +      else {
 +              l -=3D sizeof(displayname) - 4 - sizeof(displayname) / 3;
 +              (void)snprintf(displayname, sizeof displayname, "%.*s...%s",
 +                      (int)sizeof(displayname) / 3, mailname, mailname + l);
 +      }
 +jleave:       ;
 +}
 +
  /*
   * Set the size of the message vector used to construct argument
   * lists to message list functions.
 @@ -233,7 +272,7 @@ setfile(const char *name)
        edit =3D isedit;
        (void)strcpy(prevfile, mailname);
        if (name !=3D mailname)
 -              (void)strcpy(mailname, name);
 +              _update_mailname(name);
        mailsize =3D fsize(ibuf);
        (void)snprintf(tempname, sizeof(tempname),
            "%s/mail.RxXXXXXXXXXX", tmpdir);
 @@ -972,7 +1011,6 @@ newfileinfo(int omsgCount)
        struct message *mp;
        int d, n, s, t, u, mdot;
        char fname[PATHSIZE];
 -      char *ename;
 =20
        /*
         * Figure out where to set the 'dot'.  Use the first new or
 @@ -1016,23 +1054,10 @@ newfileinfo(int omsgCount)
                if (mp->m_flag & MTAGGED)
                        t++;
        }
 -      ename =3D mailname;
 -      if (getfold(fname, sizeof(fname)) >=3D 0) {
 -              char zname[PATHSIZE];
 -              size_t l;
 -              l =3D strlen(fname);
 -              if (l < sizeof(fname) - 1)
 -                      fname[l++] =3D '/';
 -              if (strncmp(fname, mailname, l) =3D=3D 0) {
 -                      (void)snprintf(zname, sizeof(zname), "+%s",
 -                          mailname + l);
 -                      ename =3D zname;
 -              }
 -      }
        /*
         * Display the statistics.
         */
 -      (void)printf("\"%s\": ", ename);
 +      (void)printf("\"%s\": ", displayname);
        {
                int cnt =3D get_abs_msgCount();
                (void)printf("%d message%s", cnt, cnt =3D=3D 1 ? "" : "s");
 


Home | Main Index | Thread Index | Old Index