poke-devel
[Top][All Lists]
Advanced

[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: Fri, 29 Nov 2019 07:21:20 +0100
User-agent: NeoMutt/20170113 (1.7.2)

PING!

On Tue, Nov 26, 2019 at 02:27:05PM +0100, John Darrington wrote:
     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, why);
              +      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
     work.
     
     J'

-- 
Avoid eavesdropping.  Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3



reply via email to

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