commit 3c5b70f243d342b665371bd2991eef14cee5a38a from: Stefan Sperling date: Thu Dec 27 19:23:37 2018 UTC always NUL-terminate paths in write_fileindex_path() commit - 60619907281df67dd34e257a01b78a876f168397 commit + 3c5b70f243d342b665371bd2991eef14cee5a38a blob - 7752302bee5c346963e1f5dcaaa9b6b354b32895 blob + f49097e88b26a862b3ef59f17f2fc1be309b880d --- lib/fileindex.c +++ lib/fileindex.c @@ -179,18 +179,19 @@ write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FIL static const struct got_error * write_fileindex_path(SHA1_CTX *ctx, const char *path, FILE *outfile) { - size_t n, len, pad; + size_t n, len, pad = 0; static const uint8_t zero[8] = { 0 }; len = strlen(path); - pad = (len % 8); + while ((len + pad) % 8 != 0) + pad++; + if (pad == 0) + pad = 8; /* NUL-terminate */ SHA1Update(ctx, path, len); n = fwrite(path, 1, len, outfile); if (n != len) return got_ferror(outfile, GOT_ERR_IO); - if (pad == 0) - return NULL; SHA1Update(ctx, zero, pad); n = fwrite(zero, 1, pad, outfile); if (n != pad)