MCPcopy Create free account
hub / github.com/OISF/libhtp / decompressFile

Method decompressFile

test/test_gunzip.cpp:65–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63protected:
64
65 virtual htp_status_t decompressFile(const char *f) {
66 // Construct complete file name
67
68 char filename[1025];
69 strncpy(filename, home, 1024);
70 strncat(filename, "/", 1024 - strlen(filename));
71 strncat(filename, f, 1024 - strlen(filename));
72
73 // Load test data
74
75 int fd = open(filename, O_RDONLY | O_BINARY);
76 if (fd < 0) {
77 //FAIL() << "Unable to open test file";
78 return HTP_ERROR;
79 }
80
81 struct stat statbuf;
82 if (fstat(fd, &statbuf) < 0) {
83 //FAIL() << "Unable to stat test file";
84 return HTP_ERROR;
85 }
86
87 htp_tx_data_t d;
88 d.tx = tx;
89 d.len = statbuf.st_size;
90 d.data = (const unsigned char *) malloc(d.len);
91 if (d.data == NULL) {
92 //FAIL() << "Memory allocation failed";
93 return HTP_ERROR;
94 }
95
96 ssize_t bytes_read = read(fd, (void *) d.data, d.len);
97 if ((bytes_read < 0)||((size_t)bytes_read != d.len)) {
98 //FAIL() << "Reading from test file failed";
99 close(fd);
100 return HTP_ERROR;
101 }
102
103 close(fd);
104
105 // Decompress
106
107 htp_status_t rc = htp_gzip_decompressor_decompress(decompressor, &d);
108
109 free((void *)d.data);
110
111 return rc;
112 }
113
114 virtual void SetUp() {
115 home = getenv("srcdir");

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected