Skip to content

Commit

Permalink
Fix cabd tests on Windows
Browse files Browse the repository at this point in the history
On Windows, the tests should write to "NUL" instead of "/dev/null".

Resolved an issue where a large unsigned int cast to an off_t resulted
in a negative value, because off_t is 32-bits instead of 64.
  • Loading branch information
micahsnyder committed Jun 7, 2020
1 parent 11f1f14 commit f4e0217
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libmspack/mspack/cabd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ static int cabd_extract(struct mscab_decompressor *base,
struct mscabd_folder_p *fol;
struct mspack_system *sys;
struct mspack_file *fh;
off_t filelen;
unsigned int filelen;

if (!self) return MSPACK_ERR_ARGS;
if (!file) return self->error = MSPACK_ERR_ARGS;
Expand Down Expand Up @@ -1049,7 +1049,7 @@ static int cabd_extract(struct mscab_decompressor *base,
* In salvage mode, don't assume block sizes, just try decoding
*/
if (!self->salvage) {
off_t maxlen = fol->base.num_blocks * CAB_BLOCKMAX;
unsigned int maxlen = fol->base.num_blocks * CAB_BLOCKMAX;
if ((file->offset + filelen) > maxlen) {
sys->message(NULL, "ERROR; file \"%s\" cannot be extracted, "
"cabinet set is incomplete", file->filename);
Expand Down
2 changes: 1 addition & 1 deletion libmspack/test/cabd_md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string.h>
#include "mspack.h"
#include <sys/stat.h>
#ifdef _WIN32
#ifdef _MSC_VER
#include "dirent.h"
#else
#include <dirent.h>
Expand Down
15 changes: 11 additions & 4 deletions libmspack/test/cabd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ unsigned int test_count = 0;
if (!(x)) {printf("%s:%d FAILED %s\n",__func__,__LINE__,#x);exit(1);} \
} while (0)


#ifdef _MSC_VER
# define DEV_NULL "NUL"
#else
# define DEV_NULL "/dev/null"
#endif

/* open where cab file doesn't exist */
void cabd_open_test_01() {
struct mscab_decompressor *cabd;
Expand Down Expand Up @@ -342,7 +349,7 @@ void cabd_extract_test_01() {
TEST(cab = cabd->open(cabd, files[i]));
TEST(cab->files != NULL);
for (file = cab->files; file; file = file->next) {
int err = cabd->extract(cabd, file, "/dev/null");
int err = cabd->extract(cabd, file, DEV_NULL);
TEST(err == MSPACK_ERR_DATAFORMAT || err == MSPACK_ERR_DECRUNCH);
}
cabd->close(cabd, cab);
Expand All @@ -363,11 +370,11 @@ void cabd_extract_test_02() {
*/
TEST(cabd = mspack_create_cab_decompressor(NULL));
TEST(cab = cabd->open(cabd, TESTFILE("cve-2014-9732-folders-segfault.cab")));
err = cabd->extract(cabd, cab->files, "/dev/null");
err = cabd->extract(cabd, cab->files, DEV_NULL);
TEST(err == MSPACK_ERR_OK);
err = cabd->extract(cabd, cab->files->next, "/dev/null");
err = cabd->extract(cabd, cab->files->next, DEV_NULL);
TEST(err == MSPACK_ERR_DATAFORMAT || err == MSPACK_ERR_DECRUNCH);
err = cabd->extract(cabd, cab->files, "/dev/null");
err = cabd->extract(cabd, cab->files, DEV_NULL);
TEST(err == MSPACK_ERR_OK);
cabd->close(cabd, cab);
mspack_destroy_cab_decompressor(cabd);
Expand Down

0 comments on commit f4e0217

Please sign in to comment.