[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.139 and 1.140

version 1.139, 2019/06/28 13:35:04 version 1.140, 2019/08/16 06:13:15
Line 1016 
Line 1016 
 percent_expand(const char *string, ...)  percent_expand(const char *string, ...)
 {  {
 #define EXPAND_MAX_KEYS 16  #define EXPAND_MAX_KEYS 16
         u_int num_keys, i, j;          u_int num_keys, i;
         struct {          struct {
                 const char *key;                  const char *key;
                 const char *repl;                  const char *repl;
         } keys[EXPAND_MAX_KEYS];          } keys[EXPAND_MAX_KEYS];
         char buf[4096];          struct sshbuf *buf;
         va_list ap;          va_list ap;
           int r;
           char *ret;
   
           if ((buf = sshbuf_new()) == NULL)
                   fatal("%s: sshbuf_new failed", __func__);
   
         /* Gather keys */          /* Gather keys */
         va_start(ap, string);          va_start(ap, string);
         for (num_keys = 0; num_keys < EXPAND_MAX_KEYS; num_keys++) {          for (num_keys = 0; num_keys < EXPAND_MAX_KEYS; num_keys++) {
Line 1039 
Line 1044 
         va_end(ap);          va_end(ap);
   
         /* Expand string */          /* Expand string */
         *buf = '\0';  
         for (i = 0; *string != '\0'; string++) {          for (i = 0; *string != '\0'; string++) {
                 if (*string != '%') {                  if (*string != '%') {
  append:   append:
                         buf[i++] = *string;                          if ((r = sshbuf_put_u8(buf, *string)) != 0) {
                         if (i >= sizeof(buf))                                  fatal("%s: sshbuf_put_u8: %s",
                                 fatal("%s: string too long", __func__);                                      __func__, ssh_err(r));
                         buf[i] = '\0';                          }
                         continue;                          continue;
                 }                  }
                 string++;                  string++;
Line 1055 
Line 1059 
                         goto append;                          goto append;
                 if (*string == '\0')                  if (*string == '\0')
                         fatal("%s: invalid format", __func__);                          fatal("%s: invalid format", __func__);
                 for (j = 0; j < num_keys; j++) {                  for (i = 0; i < num_keys; i++) {
                         if (strchr(keys[j].key, *string) != NULL) {                          if (strchr(keys[i].key, *string) != NULL) {
                                 i = strlcat(buf, keys[j].repl, sizeof(buf));                                  if ((r = sshbuf_put(buf, keys[i].repl,
                                 if (i >= sizeof(buf))                                      strlen(keys[i].repl))) != 0) {
                                         fatal("%s: string too long", __func__);                                          fatal("%s: sshbuf_put: %s",
                                               __func__, ssh_err(r));
                                   }
                                 break;                                  break;
                         }                          }
                 }                  }
                 if (j >= num_keys)                  if (i >= num_keys)
                         fatal("%s: unknown key %%%c", __func__, *string);                          fatal("%s: unknown key %%%c", __func__, *string);
         }          }
         return (xstrdup(buf));          if ((ret = sshbuf_dup_string(buf)) == NULL)
                   fatal("%s: sshbuf_dup_string failed", __func__);
           sshbuf_free(buf);
           return ret;
 #undef EXPAND_MAX_KEYS  #undef EXPAND_MAX_KEYS
 }  }
   

Legend:
Removed from v.1.139  
changed lines
  Added in v.1.140