[Top][All Lists]

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

Re: [PATCH] Allow .load only on suitable file system entries

From: John Darrington
Subject: Re: [PATCH] Allow .load only on suitable file system entries
Date: Tue, 26 Nov 2019 14:27:05 +0100
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Nov 26, 2019 at 02:13:34PM +0100, Jose E. Marchesi wrote:
         +static char *
         +pk_file_readable (const char *filename)
         +  static char errmsg[4096];
         +  struct stat statbuf;
         +  if (0 != stat (filename, &statbuf))
         +    {
         +      char *why = strerror (errno);
         +      snprintf (errmsg, 4096, _("Cannot stat %s: %s\n"), filename, 
         +      return errmsg;
         +    }
         +  if (S_ISDIR (statbuf.st_mode))
         +    {
         +      snprintf (errmsg, 4096, _("%s is a directory\n"), filename);
         +      return errmsg;
         +    }
         +  if (access (filename, R_OK) != 0)
         +    {
         +      char *why = strerror (errno);
         +      snprintf (errmsg, 4096, _("%s: file cannot be read: %s\n"),
         +              filename, why);
         +      return errmsg;
         +    }
     The stat and check for S_ISDIR can be replaced with:
       if (fstat (fileno (stream), &st) == -1 || !S_ISREG (st.st_mode))
         sprintf (errmsg, 4096, _("%s: not a regular file"));

No it can't;  Because we don't have a stream.

I'm unsure if we want to insist on file being a "regular" file.  For
example I can envisage a situation where somebody might want to use poke
to examine (or write!) a filesystem or swapspace on /dev/sd??

Also, if stat fails for any reason (eg the file doesn't exist), then the above 
would give a misleading error message.

     The check for readability can be done portably using another gnulib
     function, freadable:
       if (!freadable (stream))
         sprintf (errmsg, 4096, _("%s: file cannot be read"));

Again, we don't have  a stream at this point, so that isn't going to


reply via email to

[Prev in Thread] Current Thread [Next in Thread]