Merge branch 'jd/fix-strbuf-add-urlencode-bytes'
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Jan 2018 21:28:10 +0000 (13:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Jan 2018 21:28:10 +0000 (13:28 -0800)
Bytes with high-bit set were encoded incorrectly and made
credential helper fail.

* jd/fix-strbuf-add-urlencode-bytes:
strbuf: fix urlencode format string on signed char

1  2 
strbuf.c
diff --combined strbuf.c
index 8007be8fbafdc3f4542e27cfc9344044f71d43dc,4d5a9ce55166e801d75f60b19cc007a940bb4c9f..1df674e9194ee6d5cd5386f477745ff6639b7b65
+++ b/strbuf.c
@@@ -11,28 -11,6 +11,28 @@@ int starts_with(const char *str, const 
                        return 0;
  }
  
 +int skip_to_optional_arg_default(const char *str, const char *prefix,
 +                               const char **arg, const char *def)
 +{
 +      const char *p;
 +
 +      if (!skip_prefix(str, prefix, &p))
 +              return 0;
 +
 +      if (!*p) {
 +              if (arg)
 +                      *arg = def;
 +              return 1;
 +      }
 +
 +      if (*p != '=')
 +              return 0;
 +
 +      if (arg)
 +              *arg = p + 1;
 +      return 1;
 +}
 +
  /*
   * Used as the default ->buf value, so that people can always assume
   * buf is non NULL and ->buf is NUL terminated even for a freshly
@@@ -408,15 -386,12 +408,15 @@@ ssize_t strbuf_read(struct strbuf *sb, 
  
  ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
  {
 +      size_t oldalloc = sb->alloc;
        ssize_t cnt;
  
        strbuf_grow(sb, hint ? hint : 8192);
        cnt = xread(fd, sb->buf + sb->len, sb->alloc - sb->len - 1);
        if (cnt > 0)
                strbuf_setlen(sb, sb->len + cnt);
 +      else if (oldalloc == 0)
 +              strbuf_release(sb);
        return cnt;
  }
  
@@@ -683,7 -658,7 +683,7 @@@ static void strbuf_add_urlencode(struc
                    (!reserved && is_rfc3986_reserved(ch)))
                        strbuf_addch(sb, ch);
                else
-                       strbuf_addf(sb, "%%%02x", ch);
+                       strbuf_addf(sb, "%%%02x", (unsigned char)ch);
        }
  }