receive-pack: crash when checking with non-exist HEAD
[gitweb.git] / builtin / apply.c
index 9c5724eaccfaee62ff10eb097adc39ace351cade..622ee1674af592f4f843577f319c6883a1665f02 100644 (file)
@@ -2869,9 +2869,7 @@ static int apply_binary_fragment(struct image *img, struct patch *patch)
        case BINARY_LITERAL_DEFLATED:
                clear_image(img);
                img->len = fragment->size;
-               img->buf = xmalloc(img->len+1);
-               memcpy(img->buf, fragment->patch, img->len);
-               img->buf[img->len] = '\0';
+               img->buf = xmemdupz(fragment->patch, img->len);
                return 0;
        }
        return -1;