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

Diff for /src/usr.bin/ssh/misc.c between version 1.190 and 1.191

version 1.190, 2024/03/04 02:16:11 version 1.191, 2024/04/02 09:52:14
Line 511 
Line 511 
 #define DAYS            (HOURS * 24)  #define DAYS            (HOURS * 24)
 #define WEEKS           (DAYS * 7)  #define WEEKS           (DAYS * 7)
   
   static char *
   scandigits(char *s)
   {
           while (isdigit((unsigned char)*s))
                   s++;
           return s;
   }
   
 /*  /*
  * Convert a time string into seconds; format is   * Convert a time string into seconds; format is
  * a sequence of:   * a sequence of:
Line 535 
Line 543 
 int  int
 convtime(const char *s)  convtime(const char *s)
 {  {
         long total, secs, multiplier;          int secs, total = 0, multiplier;
         const char *p;          char *p, *os, *np, c;
         char *endp;          const char *errstr;
   
         errno = 0;          if (s == NULL || *s == '\0')
         total = 0;  
         p = s;  
   
         if (p == NULL || *p == '\0')  
                 return -1;                  return -1;
           p = os = strdup(s);     /* deal with const */
           if (os == NULL)
                   return -1;
   
         while (*p) {          while (*p) {
                 secs = strtol(p, &endp, 10);                  np = scandigits(p);
                 if (p == endp ||                  if (np) {
                     (errno == ERANGE && (secs == INT_MIN || secs == INT_MAX)) ||                          c = *np;
                     secs < 0)                          *np = '\0';
                         return -1;                  }
                   secs = (int)strtonum(p, 0, INT_MAX, &errstr);
                   if (errstr)
                           goto fail;
                   *np = c;
   
                 multiplier = 1;                  multiplier = 1;
                 switch (*endp++) {                  switch (c) {
                 case '\0':                  case '\0':
                         endp--;                          np--;   /* back up */
                         break;                          break;
                 case 's':                  case 's':
                 case 'S':                  case 'S':
Line 578 
Line 589 
                         multiplier = WEEKS;                          multiplier = WEEKS;
                         break;                          break;
                 default:                  default:
                         return -1;                          goto fail;
                 }                  }
                 if (secs > INT_MAX / multiplier)                  if (secs > INT_MAX / multiplier)
                         return -1;                          goto fail;
                 secs *= multiplier;                  secs *= multiplier;
                 if  (total > INT_MAX - secs)                  if  (total > INT_MAX - secs)
                         return -1;                          goto fail;
                 total += secs;                  total += secs;
                 if (total < 0)                  if (total < 0)
                         return -1;                          goto fail;
                 p = endp;                  p = ++np;
         }          }
           free(os);
         return total;          return total;
   fail:
           free(os);
           return -1;
 }  }
   
 #define TF_BUFS 8  #define TF_BUFS 8

Legend:
Removed from v.1.190  
changed lines
  Added in v.1.191