From cd490b6ff02d1cea5390760f457b73495661c73f Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 17 Apr 2023 17:33:53 -0400 Subject: ustar: Verify typeflag --- (limited to 'src') diff --git a/src/ustar.c b/src/ustar.c index c183560..4cc4651 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -114,10 +114,26 @@ _opkg_opk_ustar_next(struct opkg_opk_ustar *ustar, return OPKG_OPK_ERROR; } - ustar->data_size_remaining = strtol((char *) header->size, &end, - OPKG_OPK_USTAR_NUM_BASE_); - if (*end != '\0') { - return OPKG_OPK_ERROR; + switch (*header->typeflag) { + case '0': /* Regular file */ + case '7': /* High-performance or regular file */ + ustar->data_size_remaining = strtol( + (char *) header->size, &end, + OPKG_OPK_USTAR_NUM_BASE_); + if (*end != '\0') { + return OPKG_OPK_ERROR; + } + break; + case '2': /* Symbolic link */ + case '3': /* Character special file */ + case '4': /* Block special file */ + case '5': /* Directory */ + case '6': /* FIFO special file */ + ustar->data_size_remaining = 0; + break; + case '1': /* Link */ + default: /* Reserved */ + return OPKG_OPK_ERROR; /* Unsupported */ } return OPKG_OPK_OK; -- cgit v0.9.1