Commit 1ccf8652 authored by Natanael Copa's avatar Natanael Copa

Revert "abuild-tar: embed checksum for symlinks"

Tar could not handle the headers.

This reverts parts of commit 8b1a5301.
Keep the usage fixes.
parent 97030974
...@@ -42,8 +42,6 @@ struct tar_header { ...@@ -42,8 +42,6 @@ struct tar_header {
char padding[12]; /* 500-512 */ char padding[12]; /* 500-512 */
}; };
#define MAX_MD_SIZE 20
#define GET_OCTAL(s) get_octal(s, sizeof(s)) #define GET_OCTAL(s) get_octal(s, sizeof(s))
#define PUT_OCTAL(s,v) put_octal(s, sizeof(s), v) #define PUT_OCTAL(s,v) put_octal(s, sizeof(s), v)
...@@ -175,7 +173,7 @@ static int do_it(const EVP_MD *md, int cut) ...@@ -175,7 +173,7 @@ static int do_it(const EVP_MD *md, int cut)
struct tar_header hdr; struct tar_header hdr;
size_t size, aligned_size; size_t size, aligned_size;
void *ptr; void *ptr;
int r; int dohash = 0, r;
struct { struct {
char id[4]; char id[4];
uint16_t nid; uint16_t nid;
...@@ -195,34 +193,22 @@ static int do_it(const EVP_MD *md, int cut) ...@@ -195,34 +193,22 @@ static int do_it(const EVP_MD *md, int cut)
if (cut && hdr.name[0] == 0) if (cut && hdr.name[0] == 0)
return 0; return 0;
ptr = NULL;
size = GET_OCTAL(hdr.size); size = GET_OCTAL(hdr.size);
aligned_size = (size + 511) & ~511; aligned_size = (size + 511) & ~511;
if (md != NULL && if (md != NULL)
(hdr.typeflag == '0' || hdr.typeflag == '2' || dohash = (hdr.typeflag == '0' || hdr.typeflag == '7');
hdr.typeflag == '7')) { if (dohash) {
const unsigned char *src; const unsigned char *src;
unsigned char csdata[MAX_MD_SIZE];
int chksum, i; int chksum, i;
if (hdr.typeflag == '0' || hdr.typeflag == '7') { ptr = malloc(aligned_size);
ptr = malloc(aligned_size); if (full_read(STDIN_FILENO, ptr, aligned_size) != aligned_size)
if (full_read(STDIN_FILENO, ptr, aligned_size) return 1;
!= aligned_size)
return 1;
memcpy(&hdr.linkname[3], &mdinfo, sizeof(mdinfo));
EVP_Digest(ptr, size, csdata, NULL, md, NULL);
} else {
EVP_Digest(hdr.linkname, strlen(hdr.linkname),
csdata, NULL, md, NULL);
}
/* Embed to header */ memcpy(&hdr.linkname[3], &mdinfo, sizeof(mdinfo));
memcpy(&hdr.devmajor, &mdinfo, sizeof(hdr.devmajor)); EVP_Digest(ptr, size, &hdr.linkname[3+sizeof(mdinfo)],
memcpy(&hdr.devminor, &csdata[0], sizeof(hdr.devminor)); NULL, md, NULL);
memcpy(&hdr.padding, &csdata[sizeof(hdr.devminor)], sizeof(hdr.padding));
/* Recalculate checksum */ /* Recalculate checksum */
memset(hdr.chksum, ' ', sizeof(hdr.chksum)); memset(hdr.chksum, ' ', sizeof(hdr.chksum));
...@@ -235,7 +221,7 @@ static int do_it(const EVP_MD *md, int cut) ...@@ -235,7 +221,7 @@ static int do_it(const EVP_MD *md, int cut)
if (full_write(STDOUT_FILENO, &hdr, sizeof(hdr)) != sizeof(hdr)) if (full_write(STDOUT_FILENO, &hdr, sizeof(hdr)) != sizeof(hdr))
return 2; return 2;
if (ptr != NULL) { if (dohash) {
if (full_write(STDOUT_FILENO, ptr, aligned_size) != aligned_size) if (full_write(STDOUT_FILENO, ptr, aligned_size) != aligned_size)
return 2; return 2;
free(ptr); free(ptr);
...@@ -285,10 +271,6 @@ int main(int argc, char **argv) ...@@ -285,10 +271,6 @@ int main(int argc, char **argv)
md = EVP_get_digestbyname(digest); md = EVP_get_digestbyname(digest);
if (md == NULL) if (md == NULL)
return usage(); return usage();
if (EVP_MD_size(md) > MAX_MD_SIZE) {
fprintf(stderr, "digest size is too large\n");
return -1;
}
} }
return do_it(md, cut); return do_it(md, cut);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment