[BACK]Return to signify.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / signify

Diff for /src/usr.bin/signify/signify.c between version 1.48 and 1.49

version 1.48, 2014/03/06 20:04:45 version 1.49, 2014/03/07 19:49:44
Line 117 
Line 117 
         return p;          return p;
 }  }
   
 static void  
 readall(int fd, void *buf, size_t buflen, const char *filename)  
 {  
         ssize_t x;  
   
         while (buflen != 0) {  
                 x = read(fd, buf, buflen);  
                 if (x == -1)  
                         err(1, "read from %s", filename);  
                 buflen -= x;  
                 buf = (char*)buf + x;  
         }  
 }  
   
 static size_t  static size_t
 parseb64file(const char *filename, char *b64, void *buf, size_t buflen,  parseb64file(const char *filename, char *b64, void *buf, size_t buflen,
     char *comment)      char *comment)
Line 180 
Line 166 
 static uint8_t *  static uint8_t *
 readmsg(const char *filename, unsigned long long *msglenp)  readmsg(const char *filename, unsigned long long *msglenp)
 {  {
         unsigned long long msglen;          unsigned long long msglen = 0;
         uint8_t *msg;          uint8_t *msg = NULL;
         struct stat sb;          struct stat sb;
           ssize_t x, space;
         int fd;          int fd;
           const size_t chunklen = 64 * 1024;
   
         fd = xopen(filename, O_RDONLY | O_NOFOLLOW, 0);          fd = xopen(filename, O_RDONLY | O_NOFOLLOW, 0);
         if (fstat(fd, &sb) == -1)          if (fstat(fd, &sb) == 0 && S_ISREG(sb.st_mode)) {
                 err(1, "fstat on %s", filename);                  if (sb.st_size > (1UL << 30))
         if (!S_ISREG(sb.st_mode))                          errx(1, "msg too large in %s", filename);
                 errx(1, "%s must be a regular file", filename);                  space = sb.st_size + 1;
         msglen = sb.st_size;                  msg = xmalloc(space + 1);
         if (msglen > (1UL << 30))          } else {
                 errx(1, "msg too large in %s", filename);                  space = 0;
         msg = xmalloc(msglen + 1);          }
         readall(fd, msg, msglen, filename);  
           while (1) {
                   if (space == 0) {
                           space = chunklen;
                           if (!(msg = realloc(msg, msglen + space + 1)))
                                   errx(1, "realloc");
                   }
                   if ((x = read(fd, msg + msglen, space)) == -1)
                           err(1, "read from %s", filename);
                   if (x == 0)
                           break;
                   space -= x;
                   msglen += x;
                   if (msglen > (1UL << 30))
                           errx(1, "msg too large in %s", filename);
           }
   
         msg[msglen] = 0;          msg[msglen] = 0;
         close(fd);          close(fd);
   

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.49