From 3c3612d0eaec5f9b6c3c1596f43b395ad5cdcd80 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 14 Apr 2023 18:58:18 -0400 Subject: ustar: Fix read buffer --- (limited to 'src/ustar.c') diff --git a/src/ustar.c b/src/ustar.c index f403524..0a508f5 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -50,6 +50,7 @@ struct _opkg_opk_ustar_header { struct opkg_opk_ustar { struct opkg_opk_gzip *gzip; int32_t data_size_remaining; + unsigned char read_record[OPKG_OPK_USTAR_RECORD_SIZE]; }; struct opkg_opk_ustar * @@ -103,23 +104,22 @@ int opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, struct opkg_opk_ustar_member *member) { - static struct _opkg_opk_ustar_header record; + static struct _opkg_opk_ustar_header header; int ret; - if ((ret =_opkg_opk_ustar_next(ustar, &record)) != OPKG_OPK_OK) { + if ((ret =_opkg_opk_ustar_next(ustar, &header)) != OPKG_OPK_OK) { return ret; /* Error or end of archive */ } - if (record.prefix[0] != '\0') { - sprintf(member->name, "%s/%s", record.prefix, record.name); + if (header.prefix[0] != '\0') { + sprintf(member->name, "%s/%s", header.prefix, header.name); } else { - memcpy(member->name, record.name, sizeof(record.name)); - member->name[sizeof(record.name)] = '\0'; + memcpy(member->name, header.name, sizeof(header.name)); + member->name[sizeof(header.name)] = '\0'; } while (ustar->data_size_remaining > 0) { - if (opkg_opk_ustar_read(ustar, (char *) &record, NULL) == - OPKG_OPK_ERROR) { + if (opkg_opk_ustar_read(ustar, NULL, NULL) == OPKG_OPK_ERROR) { return OPKG_OPK_ERROR; } } @@ -130,22 +130,22 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, int opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member) { - static struct _opkg_opk_ustar_header record; + static struct _opkg_opk_ustar_header header; static unsigned char name[OPKG_OPK_USTAR_NAME_MAX_LEN]; int ret; for (;;) { - if ((ret =_opkg_opk_ustar_next(ustar, &record)) != OPKG_OPK_OK) + if ((ret =_opkg_opk_ustar_next(ustar, &header)) != OPKG_OPK_OK) { return OPKG_OPK_ERROR; /* Error or end (not found) */ } - if (record.prefix[0] != '\0') { - sprintf((char *) name, "%s/%s", record.prefix, - record.name); + if (header.prefix[0] != '\0') { + sprintf((char *) name, "%s/%s", header.prefix, + header.name); } else { - memcpy(name, record.name, sizeof(record.name)); - name[sizeof(record.name)] = '\0'; + memcpy(name, header.name, sizeof(header.name)); + name[sizeof(header.name)] = '\0'; } if (strcmp((char *) name, member) == 0) { @@ -155,8 +155,8 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member) } while (ustar->data_size_remaining > 0) { - if (opkg_opk_ustar_read(ustar, (char *) &record, NULL) - == OPKG_OPK_ERROR) { + if (opkg_opk_ustar_read(ustar, NULL, NULL) == + OPKG_OPK_ERROR) { return OPKG_OPK_ERROR; } } @@ -166,13 +166,13 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member) } int -opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size) +opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char **buffer, size_t *size) { if (ustar->data_size_remaining == 0) { return OPKG_OPK_END; } - switch (opkg_opk_gzip_read(ustar->gzip, buffer)) { + switch (opkg_opk_gzip_read(ustar->gzip, ustar->read_record)) { case OPKG_OPK_OK: break; case OPKG_OPK_END: @@ -180,6 +180,9 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size) return OPKG_OPK_ERROR; } + if (buffer != NULL) { + *buffer = ustar->read_record; + } if (ustar->data_size_remaining >= OPKG_OPK_USTAR_RECORD_SIZE) { if (size != NULL) { *size = OPKG_OPK_USTAR_RECORD_SIZE; -- cgit v0.9.1