Clang-format touchup

This commit is contained in:
Micah Snyder 2020-07-24 08:32:47 -07:00
parent ee60f31602
commit e2f59af30a
38 changed files with 350 additions and 378 deletions

View file

@ -359,7 +359,8 @@ void thrmgr_destroy(threadpool_t *threadpool)
return;
}
void thrmgr_wait_for_threads(threadpool_t *threadpool) {
void thrmgr_wait_for_threads(threadpool_t *threadpool)
{
if (!threadpool) {
return;
}

View file

@ -266,7 +266,7 @@ int dsresult(int sockd, int scantype, const char *filename, int *printok, int *e
char *real_filename = NULL;
if (filename) {
ret = cli_realpath((const char *) filename, &real_filename);
ret = cli_realpath((const char *)filename, &real_filename);
if (CL_SUCCESS != ret) {
logg("Failed to determine real filename of %s.\n", filename);
infected = -1;

View file

@ -185,7 +185,7 @@ static char *queue_header = NULL;
static char *multi_queue_header = NULL;
static char *clamd_header = NULL;
#define CMDHEAD " COMMAND QUEUEDSINCE FILE"
#define CMDHEAD " COMMAND QUEUEDSINCE FILE"
#define CMDHEAD2 "NO COMMAND QUEUEDSINCE FILE"
/*
@ -218,7 +218,7 @@ static void resize(void)
strncpy(clamd_header, SUMHEAD, maxx);
queue_header[maxx] = '\0';
clamd_header[maxx] = '\0';
p = queue_header + strlen(queue_header);
p = queue_header + strlen(queue_header);
while (p < queue_header + maxx)
*p++ = ' ';
p = clamd_header + strlen(clamd_header);
@ -231,7 +231,7 @@ static void resize(void)
assert(multi_queue_header);
strncpy(multi_queue_header, CMDHEAD2, maxx);
multi_queue_header[maxx] = '\0';
p = multi_queue_header + strlen(multi_queue_header);
p = multi_queue_header + strlen(multi_queue_header);
while (p < multi_queue_header + maxx)
*p++ = ' ';
}
@ -354,10 +354,12 @@ static void header(void)
wprintw(header_window, "%s", ctime(&t));
wrefresh(header_window);
/* win_start(version_window, version_color);
mvwprintw(version_window, 0, 0, "Connected to: ");
print_colored(version_window, clamd_version ? clamd_version : "Unknown");
wrefresh(version_window);*/
/*
win_start(version_window, version_color);
mvwprintw(version_window, 0, 0, "Connected to: ");
print_colored(version_window, clamd_version ? clamd_version : "Unknown");
wrefresh(version_window);
*/
werase(status_bar_window);
for (i = 0; i < sizeof(status_bar_keys) / sizeof(status_bar_keys[0]); i++) {
@ -544,7 +546,7 @@ static void print_con_info(conn_t *conn, const char *fmt, ...)
char *get_ip(const char *ip)
{
char *dupip = NULL;
char *p1 = NULL;
char *p1 = NULL;
unsigned int i;
/*
@ -621,7 +623,7 @@ char *make_ip(const char *host, const char *port)
size_t len;
int ipv6;
if (!host || !port){
if (!host || !port) {
return NULL;
}
@ -920,7 +922,7 @@ static void output_queue(size_t line, ssize_t max)
cmd[cmde - filtered_tasks[i].line] = '\0';
if (filstart) {
size_t oldline = ++line;
char *nl = strrchr(++filstart, '\n');
char *nl = strrchr(++filstart, '\n');
if (nl != NULL)
*nl = '\0';
wattron(stats_window, A_BOLD);
@ -1104,7 +1106,7 @@ static int output_stats(struct stats *stats, unsigned idx)
if (sel) {
wattroff(win, COLOR_PAIR(selected_color));
}
if ((unsigned) len > maxx) {
if ((unsigned)len > maxx) {
wattron(win, A_DIM | COLOR_PAIR(header_color));
mvwprintw(win, i, maxx - 3, "...");
wattroff(win, A_DIM | COLOR_PAIR(header_color));
@ -1123,10 +1125,12 @@ static int output_stats(struct stats *stats, unsigned idx)
snprintf(buf, sizeof(buf), "live%3u idle%3u max%3u", stats->prim_live, stats->prim_idle, stats->prim_max);
print_colored(win, buf);
show_bar(win, i++, stats->prim_live, stats->prim_idle, stats->prim_max, 0);
/* mvwprintw(win, i++, 0, "Multiscan pool : ");
snprintf(buf, sizeof(buf), "live %3u idle %3u max %3u", stats->live, stats->idle, stats->max);
print_colored(win, buf);
show_bar(win, i++, stats->live, stats->idle, stats->max, 0);*/
/*
mvwprintw(win, i++, 0, "Multiscan pool : ");
snprintf(buf, sizeof(buf), "live %3u idle %3u max %3u", stats->live, stats->idle, stats->max);
print_colored(win, buf);
show_bar(win, i++, stats->live, stats->idle, stats->max, 0);
*/
blink = 0;
if (stats->current_q > stats->biggest_queue) {
@ -1262,14 +1266,16 @@ static void parse_stats(conn_t *conn, struct stats *stats, unsigned idx)
}
for (j = 1; j < strlen(buf); j++)
buf[j] = tolower(buf[j]);
/* mvwprintw(win, i, 0, "%s", buf);
if(!val) {
i++;
continue;
}
waddch(win, ':');
print_colored(win, val);
i++;*/
/*
mvwprintw(win, i, 0, "%s", buf);
if(!val) {
i++;
continue;
}
waddch(win, ':');
print_colored(win, val);
i++;
*/
if (!strncmp("State", buf, 5)) {
if (strstr(val, "PRIMARY")) {
/* primary thread pool */
@ -1336,7 +1342,7 @@ static void help(void)
printf(" --help -h Show this help\n");
printf(" --version -V Show version\n");
printf(" --config-file=FILE -c FILE Read clamd's configuration files from FILE\n");
printf(" --defaultcolors -d Use default terminal colors\n");
printf(" --defaultcolors -d Use default terminal colors\n");
printf(" host[:port] Connect to clamd on host at port (default 3310)\n");
printf(" /path/to/clamd.socket Connect to clamd over a local socket\n");
printf("\n");
@ -1439,11 +1445,11 @@ static void setup_connections(int argc, char *argv[])
if (!conn && !opts->filename) {
soname = NULL;
} else {
soname = conn ? conn : opts->filename[i];
soname = conn ? conn : opts->filename[i];
}
global.conn[i].line = i + 1;
if (make_connection(soname, &global.conn[i]) < 0) {
EXIT_PROGRAM(FAIL_INITIAL_CONN);
EXIT_PROGRAM(FAIL_INITIAL_CONN);
}
}
@ -1519,7 +1525,7 @@ static int show_help(void)
do {
ch = getch();
/* we do need to exit on resize, because the text scroll out of
* view */
* view */
} while (ch == -1 /*|| ch == KEY_RESIZE*/);
return ch == KEY_RESIZE ? KEY_RESIZE : -1;
}

View file

@ -146,7 +146,7 @@ int main(int argc, char **argv)
if (CL_SUCCESS == onas_check_client_connection(&ctx)) {
break;
}
__attribute__ ((fallthrough));
__attribute__((fallthrough));
case CL_BREAK:
ret = 0;
logg("*Clamonacc: not setting up client\n");

View file

@ -164,11 +164,11 @@ int16_t onas_ping_clamd(struct onas_context **ctx)
char *errchk = NULL;
uint64_t i = 0;
const struct optstruct *opt = NULL;
CURL *curl = NULL;
CURL *curl = NULL;
CURLcode curlcode;
cl_error_t err = CL_SUCCESS;
int b_remote = 0;
uint16_t ret = 0;
int b_remote = 0;
uint16_t ret = 0;
int64_t timeout;
if (ctx == NULL) {
@ -238,7 +238,7 @@ int16_t onas_ping_clamd(struct onas_context **ctx)
} else if (CURLE_OK == onas_sendln(curl, "zPING", 5, timeout)) {
if (!optget((*ctx)->opts, "wait")->enabled) {
logg("PONG\n");
logg("PONG\n");
}
ret = 0;

View file

@ -199,7 +199,7 @@ int onas_dsresult(CURL *curl, int scantype, uint64_t maxstream, const char *file
char *real_filename = NULL;
if (filename) {
ret = cli_realpath((const char *) filename, &real_filename);
ret = cli_realpath((const char *)filename, &real_filename);
if (CL_SUCCESS != ret) {
logg("Failed to determine real filename of %s.\n", filename);
if (ret_code) {

View file

@ -64,7 +64,7 @@ cl_error_t onas_setup_fanotif(struct onas_context **ctx)
{
const struct optstruct *pt;
uint64_t fan_mask = FAN_EVENT_ON_CHILD;
uint64_t fan_mask = FAN_EVENT_ON_CHILD;
ddd_pid = 0;

View file

@ -749,7 +749,7 @@ static void onas_ddd_handle_extra_scanning(struct onas_context *ctx, const char
return;
}
static void onas_ddd_exit(__attribute__ ((unused)) void *arg)
static void onas_ddd_exit(__attribute__((unused)) void *arg)
{
logg("*ClamInotif: onas_ddd_exit()\n");

View file

@ -282,7 +282,7 @@ cl_error_t onas_scan_queue_start(struct onas_context **ctx)
return CL_SUCCESS;
}
static void onas_scan_queue_exit(__attribute__ ((unused)) void *arg)
static void onas_scan_queue_exit(__attribute__((unused)) void *arg)
{
logg("*ClamScanQueue: onas_scan_queue_exit()\n");

View file

@ -236,7 +236,7 @@ static cl_error_t onas_scan_thread_handle_dir(struct onas_scan_event *event_data
fres = CLAMSTAT(curr->fts_path, &sb);
if (event_data->sizelimit) {
if (fres != 0 || (uint64_t) sb.st_size > event_data->sizelimit) {
if (fres != 0 || (uint64_t)sb.st_size > event_data->sizelimit) {
/* okay to skip w/o allow/deny since dir comes from inotify
* events and (probably) won't block w/ protection enabled */
event_data->bool_opts &= ((uint16_t)~ONAS_SCTH_B_SCAN);
@ -272,7 +272,7 @@ static cl_error_t onas_scan_thread_handle_file(struct onas_scan_event *event_dat
fres = CLAMSTAT(pathname, &sb);
if (event_data->sizelimit) {
if (fres != 0 || (uint64_t) sb.st_size > event_data->sizelimit) {
if (fres != 0 || (uint64_t)sb.st_size > event_data->sizelimit) {
/* don't skip so we avoid lockups, but don't scan either;
* while it should be obvious, this will unconditionally set
* the bit in the map to 0 regardless of original orientation */

View file

@ -304,7 +304,7 @@ static void scanfile(const char *filename, struct cl_engine *engine, const struc
goto done;
}
ret = cli_realpath((const char *) filename, &real_filename);
ret = cli_realpath((const char *)filename, &real_filename);
if (CL_SUCCESS != ret) {
logg("Failed to determine real filename of %s.\n", filename);
goto done;

View file

@ -745,7 +745,7 @@ static fc_error_t initialize(struct optstruct *opts)
fc_error_t status = FC_EARG;
cl_error_t cl_init_retcode;
fc_config fcConfig;
char *tempDirectory = NULL;
char *tempDirectory = NULL;
const struct optstruct *logFileOpt = NULL;
STATBUF statbuf;
@ -793,14 +793,14 @@ static fc_error_t initialize(struct optstruct *opts)
errno = 0;
if ((user = getpwnam(optget(opts, "DatabaseOwner")->strarg)) == NULL) {
logg("ERROR: Failed to get information about user \"%s\".\n",
optget(opts, "DatabaseOwner")->strarg);
optget(opts, "DatabaseOwner")->strarg);
if (errno == 0) {
logg("Create the \"%s\" user account for freshclam to use, or set the DatabaseOwner config option in freshclam.conf to a different user.\n",
optget(opts, "DatabaseOwner")->strarg);
optget(opts, "DatabaseOwner")->strarg);
logg("For more information, see https://www.clamav.net/documents/installing-clamav-on-unix-linux-macos-from-source\n");
} else {
logg("An unexpected error occurred when attempting to query the \"%s\" user account.\n",
optget(opts, "DatabaseOwner")->strarg);
optget(opts, "DatabaseOwner")->strarg);
}
status = FC_EDBDIRACCESS;
goto done;
@ -911,7 +911,7 @@ static fc_error_t initialize(struct optstruct *opts)
fcConfig.localIP = (optget(opts, "LocalIPAddress"))->strarg;
/* Select a path for the temp directory: databaseDirectory/tmp */
tempDirectory = cli_gentemp_with_prefix(fcConfig.databaseDirectory, "tmp");
tempDirectory = cli_gentemp_with_prefix(fcConfig.databaseDirectory, "tmp");
fcConfig.tempDirectory = tempDirectory;
/* Store the path of the temp directory so we can delete it later. */

View file

@ -225,7 +225,7 @@ int blobAddData(blob *b, const unsigned char *data, size_t len)
b->size = growth;
b->data = cli_malloc(growth);
if (NULL == b->data){
if (NULL == b->data) {
b->size = 0;
return -1;
}
@ -245,7 +245,7 @@ int blobAddData(blob *b, const unsigned char *data, size_t len)
b->size = (off_t)len * 4;
b->data = cli_malloc(b->size);
if (NULL == b->data){
if (NULL == b->data) {
b->size = 0;
return -1;
}

View file

@ -249,7 +249,7 @@ enum lzma_returncode {
* Bzip2 return codes
*/
enum bzip2_returncode {
BZIP2_OK = 0, /* Function returned without error */
BZIP2_OK = 0, /* Function returned without error */
BZIP2_SEQUENCE_ERROR = -1,
BZIP2_PARAM_ERROR = -2,
BZIP2_MEM_ERROR = -3,

View file

@ -32,5 +32,4 @@ cl_error_t cache_check(unsigned char *hash, cli_ctx *ctx);
int cli_cache_init(struct cl_engine *engine);
void cli_cache_destroy(struct cl_engine *engine);
#endif

View file

@ -98,7 +98,7 @@ static void sanitname(char *name)
int cli_scancpio_old(cli_ctx *ctx)
{
struct cpio_hdr_old hdr_old;
char * fmap_name = NULL;
char *fmap_name = NULL;
char name[513];
unsigned int file = 0, trailer = 0;
uint32_t filesize, namesize, hdr_namesize;

View file

@ -948,9 +948,9 @@ cl_error_t cli_codepage_to_utf8(char* in, size_t in_size, uint16_t codepage, cha
}
for (attempt = 1; attempt <= 3; attempt++) {
char * inbuf = in;
size_t inbufsize = in_size;
size_t iconvRet = -1;
char* inbuf = in;
size_t inbufsize = in_size;
size_t iconvRet = -1;
size_t outbytesleft = 0;
char* out_utf8_tmp = NULL;

View file

@ -152,7 +152,7 @@ scan_overlay:
// Is there an overlay?
if (offset < map->len) {
cl_error_t recRetVal = cli_magic_scan_nested_fmap_type(map, offset, map->len - offset, ctx, CL_TYPE_ANY, NULL);
retVal = recRetVal != CL_SUCCESS ? recRetVal : retVal;
retVal = recRetVal != CL_SUCCESS ? recRetVal : retVal;
}
return retVal;

View file

@ -37,7 +37,7 @@
#include "scanners.h"
#include "entconv.h"
#define DECMPFS_HEADER_MAGIC 0x636d7066
#define DECMPFS_HEADER_MAGIC 0x636d7066
#define DECMPFS_HEADER_MAGIC_LE 0x66706d63
static void headerrecord_to_host(hfsHeaderRecord *);
@ -51,12 +51,12 @@ static int hfsplus_volumeheader(cli_ctx *, hfsPlusVolumeHeader **);
static int hfsplus_readheader(cli_ctx *, hfsPlusVolumeHeader *, hfsNodeDescriptor *,
hfsHeaderRecord *, int, const char *);
static cl_error_t hfsplus_scanfile(cli_ctx *, hfsPlusVolumeHeader *, hfsHeaderRecord *,
hfsPlusForkData *, const char *, char **, char *);
hfsPlusForkData *, const char *, char **, char *);
static int hfsplus_validate_catalog(cli_ctx *, hfsPlusVolumeHeader *, hfsHeaderRecord *);
static int hfsplus_fetch_node(cli_ctx *, hfsPlusVolumeHeader *, hfsHeaderRecord *,
hfsHeaderRecord *, hfsPlusForkData *, uint32_t, uint8_t *);
static cl_error_t hfsplus_walk_catalog(cli_ctx *, hfsPlusVolumeHeader *, hfsHeaderRecord *,
hfsHeaderRecord *, hfsHeaderRecord *, const char *);
hfsHeaderRecord *, hfsHeaderRecord *, const char *);
/* Header Record : fix endianness for useful fields */
static void headerrecord_to_host(hfsHeaderRecord *hdr)
@ -315,7 +315,7 @@ static int hfsplus_readheader(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, hfsN
* @return cl_error_t
*/
static cl_error_t hfsplus_scanfile(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, hfsHeaderRecord *extHeader,
hfsPlusForkData *fork, const char *dirname, char** filename, char *orig_filename)
hfsPlusForkData *fork, const char *dirname, char **filename, char *orig_filename)
{
hfsPlusExtentDescriptor *currExt;
const uint8_t *mPtr = NULL;
@ -431,8 +431,7 @@ static cl_error_t hfsplus_scanfile(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader,
/* if successful so far, scan the output */
if (filename) {
*filename = tmpname;
}
else {
} else {
if (ret == CL_CLEAN) {
ret = cli_magic_scan_desc(ofd, tmpname, ctx, orig_filename);
}
@ -484,7 +483,7 @@ static cl_error_t hfsplus_check_attribute(cli_ctx *ctx, hfsPlusVolumeHeader *vol
uint8_t *nodeBuf = NULL;
uint32_t thisNode, nodeLimit, nodesScanned = 0;
cl_error_t ret = CL_SUCCESS;
int foundAttr = 0;
int foundAttr = 0;
if (found) {
*found = 0;
@ -564,14 +563,14 @@ static cl_error_t hfsplus_check_attribute(cli_ctx *ctx, hfsPlusVolumeHeader *vol
recordStart = nextStart;
if (recordStart + sizeof(attrKey) >= topOfOffsets) {
cli_dbgmsg("hfsplus_check_attribute: Not enough data for an attribute key at location %x for %u!\n",
nextStart, recordNum);
nextStart, recordNum);
ret = CL_EFORMAT;
break;
}
memcpy(&attrKey, &nodeBuf[recordStart], sizeof(attrKey));
attrKey.keyLength = be16_to_host(attrKey.keyLength);
attrKey.cnid = be32_to_host(attrKey.cnid);
attrKey.keyLength = be16_to_host(attrKey.keyLength);
attrKey.cnid = be32_to_host(attrKey.cnid);
attrKey.startBlock = be32_to_host(attrKey.startBlock);
attrKey.nameLength = be16_to_host(attrKey.nameLength);
@ -594,7 +593,7 @@ static cl_error_t hfsplus_check_attribute(cli_ctx *ctx, hfsPlusVolumeHeader *vol
if (attrKey.cnid == expectedCnid && attrKey.nameLength * 2 == nameLen && memcmp(&nodeBuf[recordStart + 14], name, nameLen) == 0) {
memcpy(&attrRec, &(nodeBuf[recordStart + sizeof(hfsPlusAttributeKey) + attrKey.nameLength * 2]), sizeof(attrRec));
attrRec.recordType = be32_to_host(attrRec.recordType);
attrRec.recordType = be32_to_host(attrRec.recordType);
attrRec.attributeSize = be32_to_host(attrRec.attributeSize);
if (attrRec.recordType != HFSPLUS_RECTYPE_INLINE_DATA_ATTRIBUTE) {
@ -614,7 +613,7 @@ static cl_error_t hfsplus_check_attribute(cli_ctx *ctx, hfsPlusVolumeHeader *vol
memcpy(record, &(nodeBuf[recordStart + sizeof(hfsPlusAttributeKey) + attrKey.nameLength * 2 + sizeof(attrRec)]), attrRec.attributeSize);
*recordSize = attrRec.attributeSize;
ret = CL_SUCCESS;
ret = CL_SUCCESS;
foundAttr = 1;
break;
}
@ -639,7 +638,7 @@ static int hfsplus_fetch_node(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, hfsH
uint32_t curBlock;
uint32_t extentNum = 0, realFileBlock;
uint32_t readSize;
size_t fileOffset = 0;
size_t fileOffset = 0;
uint32_t searchBlock;
uint32_t buffOffset = 0;
@ -667,7 +666,7 @@ static int hfsplus_fetch_node(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, hfsH
for (curBlock = startBlock; curBlock <= endBlock; ++curBlock) {
foundBlock = 0;
foundBlock = 0;
searchBlock = curBlock;
/* Find which extent has that block */
for (extentNum = 0; extentNum < 8; extentNum++) {
@ -707,12 +706,11 @@ static int hfsplus_fetch_node(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, hfsH
return CL_EFORMAT;
}
fileOffset = realFileBlock * volHeader->blockSize;
readSize = volHeader->blockSize;
readSize = volHeader->blockSize;
if (curBlock == startBlock) {
fileOffset += startOffset;
}
else if (curBlock == endBlock) {
} else if (curBlock == endBlock) {
readSize = endSize;
}
@ -734,7 +732,7 @@ static cl_error_t hfsplus_seek_to_cmpf_resource(int fd, size_t *size)
hfsPlusReferenceEntry entry;
int i;
int cmpfInstanceIdx = -1;
int curInstanceIdx = 0;
int curInstanceIdx = 0;
size_t dataOffset;
uint32_t dataLength;
cl_error_t ret = CL_SUCCESS;
@ -751,9 +749,9 @@ static cl_error_t hfsplus_seek_to_cmpf_resource(int fd, size_t *size)
}
resourceHeader.dataOffset = be32_to_host(resourceHeader.dataOffset);
resourceHeader.mapOffset = be32_to_host(resourceHeader.mapOffset);
resourceHeader.mapOffset = be32_to_host(resourceHeader.mapOffset);
resourceHeader.dataLength = be32_to_host(resourceHeader.dataLength);
resourceHeader.mapLength = be32_to_host(resourceHeader.mapLength);
resourceHeader.mapLength = be32_to_host(resourceHeader.mapLength);
//TODO: Need to get offset of cmpf resource in data stream
@ -770,9 +768,9 @@ static cl_error_t hfsplus_seek_to_cmpf_resource(int fd, size_t *size)
}
resourceMap.resourceForkAttributes = be16_to_host(resourceMap.resourceForkAttributes);
resourceMap.typeListOffset = be16_to_host(resourceMap.typeListOffset);
resourceMap.nameListOffset = be16_to_host(resourceMap.nameListOffset);
resourceMap.typeCount = be16_to_host(resourceMap.typeCount);
resourceMap.typeListOffset = be16_to_host(resourceMap.typeListOffset);
resourceMap.nameListOffset = be16_to_host(resourceMap.nameListOffset);
resourceMap.typeCount = be16_to_host(resourceMap.typeCount);
for (i = 0; i < resourceMap.typeCount + 1; ++i) {
if (cli_readn(fd, &resourceType, sizeof(resourceType)) != sizeof(resourceType)) {
@ -780,7 +778,7 @@ static cl_error_t hfsplus_seek_to_cmpf_resource(int fd, size_t *size)
ret = CL_EREAD;
goto done;
}
resourceType.instanceCount = be16_to_host(resourceType.instanceCount);
resourceType.instanceCount = be16_to_host(resourceType.instanceCount);
resourceType.referenceListOffset = be16_to_host(resourceType.referenceListOffset);
if (memcmp(resourceType.type, "cmpf", 4) == 0) {
@ -848,7 +846,7 @@ static int hfsplus_read_block_table(int fd, uint32_t *numBlocks, hfsPlusResource
}
*numBlocks = le32_to_host(*numBlocks); //Let's do a little little endian just for fun, shall we?
*table = cli_malloc(sizeof(hfsPlusResourceBlockTable) * *numBlocks);
*table = cli_malloc(sizeof(hfsPlusResourceBlockTable) * *numBlocks);
if (!*table) {
cli_dbgmsg("hfsplus_read_block_table: Failed to allocate memory for block table\n");
return CL_EMEM;
@ -868,23 +866,22 @@ static int hfsplus_read_block_table(int fd, uint32_t *numBlocks, hfsPlusResource
return CL_SUCCESS;
}
/* Given the catalog and other details, scan all the volume contents */
static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, hfsHeaderRecord *catHeader,
hfsHeaderRecord *extHeader, hfsHeaderRecord *attrHeader, const char *dirname)
hfsHeaderRecord *extHeader, hfsHeaderRecord *attrHeader, const char *dirname)
{
cl_error_t ret = CL_SUCCESS;
unsigned int has_alerts = 0;
uint32_t thisNode, nodeLimit, nodesScanned = 0;
uint16_t nodeSize, recordNum, topOfOffsets;
uint16_t recordStart, nextDist, nextStart;
uint8_t *nodeBuf = NULL;
uint8_t *nodeBuf = NULL;
const uint8_t COMPRESSED_ATTR[] = {0, 'c', 0, 'o', 0, 'm', 0, '.', 0, 'a', 0, 'p', 0, 'p', 0, 'l', 0, 'e', 0, '.', 0, 'd', 0, 'e', 0, 'c', 0, 'm', 0, 'p', 0, 'f', 0, 's'};
char *tmpname = NULL;
uint8_t *uncompressed = NULL;
int ofd = -1;
char* name_utf8 = NULL;
size_t name_utf8_size = 0;
char *tmpname = NULL;
uint8_t *uncompressed = NULL;
int ofd = -1;
char *name_utf8 = NULL;
size_t name_utf8_size = 0;
nodeLimit = MIN(catHeader->totalNodes, HFSPLUS_NODE_LIMIT);
thisNode = catHeader->firstLeafNode;
@ -968,12 +965,12 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
/* Collect filename */
if (keylen >= 6) {
uint16_t name_length = (nodeBuf[recordStart + 2 + 4] << 8) | nodeBuf[recordStart + 2 + 4 + 1];
char *index = (char*)&nodeBuf[recordStart + 2 + 4 + 2];
char *index = (char *)&nodeBuf[recordStart + 2 + 4 + 2];
if ((name_length > 0) && (name_length * 2 <= keylen - 2 - 4)) {
/*
* The name is contained in nodeBuf[recordStart + 2 + 4 + 2 : recordStart + 2 + 4 + 2 + name_length * 2] encoded as UTF-16BE.
*/
if (CL_SUCCESS != cli_codepage_to_utf8((char*)index, name_length * 2, 1201, &name_utf8, &name_utf8_size)) {
if (CL_SUCCESS != cli_codepage_to_utf8((char *)index, name_length * 2, 1201, &name_utf8, &name_utf8_size)) {
cli_errmsg("hfsplus_walk_catalog: failed to convert UTF-16BE to UTF-8\n");
name_utf8 = NULL;
}
@ -1002,7 +999,7 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
memcpy(&fileRec, &(nodeBuf[recordStart + keylen + 2]), sizeof(hfsPlusCatalogFile));
/* Only scan files */
fileRec.fileID = be32_to_host(fileRec.fileID);
fileRec.fileID = be32_to_host(fileRec.fileID);
fileRec.permissions.fileMode = be16_to_host(fileRec.permissions.fileMode);
if ((fileRec.permissions.fileMode & HFS_MODE_TYPEMASK) == HFS_MODE_FILE) {
int compressed = 0;
@ -1034,9 +1031,9 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
//According to the doc, it should be in big endian.
if (header.magic == DECMPFS_HEADER_MAGIC_LE) {
header.magic = cbswap32(header.magic);
header.magic = cbswap32(header.magic);
header.compressionType = cbswap32(header.compressionType);
header.fileSize = cbswap64(header.fileSize);
header.fileSize = cbswap64(header.fileSize);
}
if (header.magic != DECMPFS_HEADER_MAGIC) {
@ -1071,8 +1068,7 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
}
written = cli_writen(ofd, &attribute[sizeof(header) + 1], header.fileSize);
}
else {
} else {
z_stream stream;
int z_ret;
@ -1089,13 +1085,13 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
break;
}
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.avail_in = attributeSize - sizeof(header);
stream.next_in = &attribute[sizeof(header)];
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.avail_in = attributeSize - sizeof(header);
stream.next_in = &attribute[sizeof(header)];
stream.avail_out = header.fileSize;
stream.next_out = uncompressed;
stream.next_out = uncompressed;
z_ret = inflateInit2(&stream, 15 /* maximum windowBits size */);
if (z_ret != Z_OK) {
@ -1151,8 +1147,8 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
//resource, that its type is correct, and that its
//name is cmpf.
char *resourceFile = NULL;
int ifd = -1;
size_t written = 0;
int ifd = -1;
size_t written = 0;
//4096 is an approximative value, there should be
//at least 16 (resource header) + 30 (map header) +
@ -1181,37 +1177,32 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
if ((ifd = safe_open(resourceFile, O_RDONLY | O_BINARY)) == -1) {
cli_dbgmsg("hfsplus_walk_catalog: Failed to open temporary file %s\n", resourceFile);
ret = CL_EOPEN;
}
else {
} else {
size_t resourceLen;
if ((ret = hfsplus_seek_to_cmpf_resource(ifd, &resourceLen)) != CL_SUCCESS) {
cli_dbgmsg("hfsplus_walk_catalog: Failed to find cmpf resource in resource fork\n");
}
else {
} else {
hfsPlusResourceBlockTable *table = NULL;
uint32_t numBlocks;
uint32_t dataOffset = lseek(ifd, 0, SEEK_CUR);
if ((ret = hfsplus_read_block_table(ifd, &numBlocks, &table)) != CL_SUCCESS) {
cli_dbgmsg("hfsplus_walk_catalog: Failed to read block table\n");
}
else {
} else {
uint8_t block[4096];
uint8_t uncompressed[4096];
unsigned curBlock;
for (curBlock = 0; ret == CL_SUCCESS && curBlock < numBlocks; ++curBlock) {
off_t blockOffset = dataOffset + table[curBlock].offset;
size_t curOffset;
size_t readLen;
z_stream stream;
int streamBeginning = 1;
int streamBeginning = 1;
int streamCompressed = 0;
cli_dbgmsg("Handling block %u of %" PRIu32 " at offset %" PRIi64 " (size %u)\n", curBlock, numBlocks, (int64_t)blockOffset, table[curBlock].length);
if (lseek(ifd, blockOffset, SEEK_SET) != blockOffset) {
cli_dbgmsg("hfsplus_walk_catalog: Failed to seek to beginning of block\n");
ret = CL_ESEEK;
@ -1235,13 +1226,13 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
if (streamCompressed) {
cli_dbgmsg("Current stream is compressed\n");
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.avail_in = readLen;
stream.next_in = block;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.avail_in = readLen;
stream.next_in = block;
stream.avail_out = sizeof(uncompressed);
stream.next_out = uncompressed;
stream.next_out = uncompressed;
if ((ret = inflateInit2(&stream, 15)) != Z_OK) {
cli_dbgmsg("hfsplus_walk_catalog: inflateInit2 failed (%d)\n", ret);
@ -1252,10 +1243,10 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
}
if (streamCompressed) {
stream.avail_in = readLen;
stream.next_in = block;
stream.avail_in = readLen;
stream.next_in = block;
stream.avail_out = sizeof(uncompressed);
stream.next_out = uncompressed;
stream.next_out = uncompressed;
while (stream.avail_in > 0) {
ret = inflate(&stream, Z_NO_FLUSH);
@ -1272,10 +1263,9 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
}
written += sizeof(uncompressed) - stream.avail_out;
stream.avail_out = sizeof(uncompressed);
stream.next_out = uncompressed;
stream.next_out = uncompressed;
}
}
else {
} else {
if (cli_writen(ofd, &block[streamBeginning ? 1 : 0], readLen - (streamBeginning ? 1 : 0)) != readLen - (streamBeginning ? 1 : 0)) {
cli_dbgmsg("hfsplus_walk_catalog: Failed to write to temporary file\n");
ret = CL_EWRITE;
@ -1292,8 +1282,7 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
if ((ret = inflateEnd(&stream)) != Z_OK) {
cli_dbgmsg("hfsplus_walk_catalog: inflateEnd failed (%d)\n", ret);
ret = CL_EFORMAT;
}
else {
} else {
ret = CL_SUCCESS;
}
}
@ -1305,7 +1294,6 @@ static cl_error_t hfsplus_walk_catalog(cli_ctx *ctx, hfsPlusVolumeHeader *volHea
free(table);
table = NULL;
}
}
}
}
@ -1482,13 +1470,11 @@ cli_dbgmsg("sizeof(hfsNodeDescriptor) is %lu\n", sizeof(hfsNodeDescriptor));
ret = hfsplus_readheader(ctx, volHeader, &attributesFileDesc, &attributesFileHeader, HFS_FILETREE_ATTRIBUTES, "attributesFile");
if (ret == CL_SUCCESS) {
hasAttributesFileHeader = 1;
}
else {
} else {
hasAttributesFileHeader = 0;
ret = CL_SUCCESS;
ret = CL_SUCCESS;
}
/* Create temp folder for contents */
if (!(targetdir = cli_gentemp_with_prefix(ctx->sub_tmpdir, "hfsplus-tmp"))) {
cli_errmsg("cli_scanhfsplus: cli_gentemp failed\n");

View file

@ -308,18 +308,18 @@ struct hfsPlusResourceHeader {
typedef struct hfsPlusResourceHeader hfsPlusResourceHeader;
struct hfsPlusResourceMap {
uint8_t reserved1[16];
uint8_t reserved1[16];
uint32_t reserved2;
uint16_t reserved3;
uint16_t resourceForkAttributes;
uint16_t typeListOffset;
uint16_t nameListOffset;
int16_t typeCount;
int16_t typeCount;
} __attribute__((__packed__));
typedef struct hfsPlusResourceMap hfsPlusResourceMap;
struct hfsPlusResourceType {
char type[4];
char type[4];
uint16_t instanceCount;
uint16_t referenceListOffset;
} __attribute__((__packed__));
@ -327,9 +327,9 @@ typedef struct hfsPlusResourceType hfsPlusResourceType;
struct hfsPlusReferenceEntry {
uint16_t resourceId;
int16_t resourceNameOffset;
uint8_t resourceAttributes;
uint8_t resourceDataOffset[3];
int16_t resourceNameOffset;
uint8_t resourceAttributes;
uint8_t resourceDataOffset[3];
uint32_t reserved1;
} __attribute__((__packed__));
typedef struct hfsPlusReferenceEntry hfsPlusReferenceEntry;
@ -340,11 +340,9 @@ struct hfsPlusResourceBlockTable {
} __attribute__((__packed__));
typedef struct hfsPlusResourceBlockTable hfsPlusResourceBlockTable;
#define HFSPLUS_COMPRESSION_INLINE 0x03
#define HFSPLUS_COMPRESSION_RESOURCE 0x04
#ifdef HAVE_PRAGMA_PACK
#pragma pack()
#endif

View file

@ -30,6 +30,6 @@
#include "uniq.h"
int cli_ole2_extract(const char *dirname, cli_ctx *ctx, struct uniq **files, int *has_vba, int *has_xlm);
char * cli_ole2_get_property_name2(const char *name, int size);
char *cli_ole2_get_property_name2(const char *name, int size);
#endif

View file

@ -119,7 +119,7 @@ static cl_error_t ooxml_updatelimits(int fd, cli_ctx *ctx)
static cl_error_t ooxml_parse_document(int fd, cli_ctx *ctx)
{
cl_error_t ret = CL_SUCCESS;
cl_error_t ret = CL_SUCCESS;
xmlTextReaderPtr reader = NULL;
cli_dbgmsg("in ooxml_parse_document\n");
@ -231,8 +231,8 @@ static cl_error_t ooxml_content_cb(int fd, const char *filepath, cli_ctx *ctx, c
CT = PN = NULL;
while (xmlTextReaderMoveToNextAttribute(reader) == 1) {
localname = xmlTextReaderConstLocalName(reader);
value = xmlTextReaderConstValue(reader);
localname = xmlTextReaderConstLocalName(reader);
value = xmlTextReaderConstValue(reader);
if (localname == NULL || value == NULL) continue;
if (!xmlStrcmp(localname, (const xmlChar *)"ContentType")) {
@ -424,8 +424,8 @@ cli_file_t cli_ooxml_filetype(cli_ctx *ctx, fmap_t *map)
cl_error_t cli_process_ooxml(cli_ctx *ctx, int type)
{
#if HAVE_LIBXML2 && HAVE_JSON
uint32_t loff = 0;
cl_error_t ret = CL_SUCCESS;
uint32_t loff = 0;
cl_error_t ret = CL_SUCCESS;
cli_dbgmsg("in cli_process_ooxml\n");
if (!ctx) {

View file

@ -150,9 +150,9 @@ typedef struct cli_ctx_container_tag {
/* internal clamav context */
typedef struct cli_ctx_tag {
char *target_filepath; /**< (optional) The filepath of the original scan target */
const char *sub_filepath; /**< (optional) The filepath of the current file being parsed. May be a temp file. */
char *sub_tmpdir; /**< The directory to store tmp files at this recursion depth. */
char *target_filepath; /**< (optional) The filepath of the original scan target */
const char *sub_filepath; /**< (optional) The filepath of the current file being parsed. May be a temp file. */
char *sub_tmpdir; /**< The directory to store tmp files at this recursion depth. */
const char **virname;
unsigned int num_viruses;
unsigned long int *scanned;

View file

@ -2097,7 +2097,7 @@ static void pdf_parse_trailer(struct pdf_struct *pdf, const char *s, long length
if (newID) {
free(pdf->fileID);
pdf->fileID = newID;
pdf->fileID = newID;
pdf->fileIDlen = newIDlen;
}
}

View file

@ -207,7 +207,7 @@ cl_error_t cli_parsepng(cli_ctx *ctx)
offadjust = offset + sz - 8;
left_comp_read = MIN(map->len - offset + sz - 8, sz);
zstrm.next_in = (uint8_t *) buffer;
zstrm.next_in = (uint8_t *)buffer;
zstrm.avail_in = MIN(toread, left_comp_read);
left_comp_read -= zstrm.avail_in;
@ -254,12 +254,12 @@ cl_error_t cli_parsepng(cli_ctx *ctx)
}
toread = toread_check;
offset += toread;
zstrm.next_in = (uint8_t *) buffer;
zstrm.next_in = (uint8_t *)buffer;
zstrm.avail_in = toread;
left_comp_read -= toread;
}
zstrm.next_out = (uint8_t *) outbuf;
zstrm.next_out = (uint8_t *)outbuf;
zstrm.avail_out = BUFFER_SIZE;
err = inflate(&zstrm, Z_NO_FLUSH);
uncomp_data += (BUFFER_SIZE - zstrm.avail_out);

View file

@ -154,9 +154,9 @@ cl_error_t regex_list_match(struct regex_matcher *matcher, char *real_url, const
struct regex_list *regex;
size_t real_len, display_len, buffer_len;
char *buffer = NULL;
char *bufrev = NULL;
cl_error_t rc = CL_SUCCESS;
char *buffer = NULL;
char *bufrev = NULL;
cl_error_t rc = CL_SUCCESS;
//int filter_search_rc = 0;
int root;
struct cli_ac_data mdata;

View file

@ -4609,7 +4609,7 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char *
cli_set_container(&ctx, CL_TYPE_ANY, 0);
ctx.dconf = (struct cli_dconf *)engine->dconf;
ctx.cb_ctx = context;
fmap_head = cli_calloc(sizeof(fmap_t *), ctx.engine->maxreclevel + 3);
fmap_head = cli_calloc(sizeof(fmap_t *), ctx.engine->maxreclevel + 3);
if (!fmap_head) {
rc = CL_EMEM;
goto done;
@ -4625,7 +4625,7 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char *
* fmap's file descriptor in the virus found callback (like for deferred
* low-seveerity alerts).
*/
ctx.fmap = fmap_head + 1;
ctx.fmap = fmap_head + 1;
*ctx.fmap = map;
perf_init(&ctx);

View file

@ -86,8 +86,7 @@ static int td_isascii(const unsigned char *buf, unsigned int len)
if ((len >= 3) &&
(buf[0] == 0xEF) &&
(buf[1] == 0xBB) &&
(buf[2] == 0xBF))
{
(buf[2] == 0xBF)) {
return 0;
}

View file

@ -614,7 +614,7 @@ static unsigned int parse_local_file_header(
char name[256];
char *original_filename = NULL;
uint32_t csize, usize;
int virus_found = 0;
int virus_found = 0;
unsigned int size_of_fileheader_and_data = 0;
if (!(local_header = fmap_need_off(map, loff, SIZEOF_LOCAL_HEADER))) {

View file

@ -280,14 +280,15 @@ vba_read_project_strings(int fd, int big_endian)
return ret;
}
static size_t vba_normalize(unsigned char *buffer, size_t size) {
static size_t vba_normalize(unsigned char *buffer, size_t size)
{
enum {
NORMAL = 0,
IN_STRING = 1,
UNDERSCORE = 2,
NORMAL = 0,
IN_STRING = 1,
UNDERSCORE = 2,
UNDERSCORE_CR = 3,
SPACE = 5,
} state = NORMAL;
SPACE = 5,
} state = NORMAL;
size_t o = 0;
size_t i;
for (i = 0; i < size; ++i) {
@ -297,8 +298,7 @@ static size_t vba_normalize(unsigned char *buffer, size_t size) {
case '"':
if (state == IN_STRING) {
state = NORMAL;
}
else if (state == NORMAL || state == UNDERSCORE || state == SPACE) {
} else if (state == NORMAL || state == UNDERSCORE || state == SPACE) {
state = IN_STRING;
}
buffer[o++] = '"';
@ -319,13 +319,12 @@ static size_t vba_normalize(unsigned char *buffer, size_t size) {
if (state == UNDERSCORE) {
o -= 1;
state = SPACE;
}
else if (state == UNDERSCORE_CR) {
} else if (state == UNDERSCORE_CR) {
o -= 2;
state = SPACE;
}
else {
buffer[o++] = '\n';;
} else {
buffer[o++] = '\n';
;
}
break;
case '\t':
@ -340,14 +339,12 @@ static size_t vba_normalize(unsigned char *buffer, size_t size) {
default:
if (state == NORMAL || state == UNDERSCORE || state == SPACE) {
if (buffer[i] >= 'A' && buffer[i] <= 'Z') {
buffer[o++] = (unsigned char) tolower((int) buffer[i]);
}
else {
buffer[o++] = (unsigned char)tolower((int)buffer[i]);
} else {
buffer[o++] = buffer[i];
}
state = NORMAL;
}
else {
} else {
buffer[o++] = buffer[i];
}
break;
@ -356,23 +353,22 @@ static size_t vba_normalize(unsigned char *buffer, size_t size) {
return o;
}
/**
* Read a VBA project in an OLE directory.
* Contrary to cli_vba_readdir, this function uses the dir file to locate VBA modules.
*/
cl_error_t
cli_vba_readdir_new(cli_ctx* ctx, const char *dir, struct uniq *U, const char *hash, uint32_t which, int *tempfd)
cli_vba_readdir_new(cli_ctx *ctx, const char *dir, struct uniq *U, const char *hash, uint32_t which, int *tempfd)
{
cl_error_t ret = CL_SUCCESS;
char fullname[1024];
int fd = -1;
int fd = -1;
unsigned char *data = NULL;
size_t data_len;
size_t data_offset;
const char *stream_name = NULL;
char *tempfile = NULL;
uint16_t codepage = CODEPAGE_ISO8859_1;
char *tempfile = NULL;
uint16_t codepage = CODEPAGE_ISO8859_1;
unsigned i;
char *mbcs_name = NULL, *utf16_name = NULL;
size_t mbcs_name_size = 0, utf16_name_size = 0;
@ -401,65 +397,65 @@ cl_error_t
}
if ((ret = cli_gentempfd(ctx->engine->tmpdir, &tempfile, tempfd)) != CL_SUCCESS) {
cli_warnmsg("vba_readdir_new: VBA project cannot be dumped to file\n");
goto done;
cli_warnmsg("vba_readdir_new: VBA project cannot be dumped to file\n");
goto done;
}
cli_dbgmsg("Dumping VBA project from dir %s to file %s\n", fullname, tempfile);
#define CLI_WRITEN(msg, size) \
do { \
if (cli_writen(*tempfd, msg, size) != size) { \
#define CLI_WRITEN(msg, size) \
do { \
if (cli_writen(*tempfd, msg, size) != size) { \
cli_warnmsg("vba_readdir_new: Failed to write to output file\n"); \
ret = CL_EWRITE; \
goto done; \
} \
ret = CL_EWRITE; \
goto done; \
} \
} while (0)
#define CLI_WRITENHEX(msg, size) \
do { \
unsigned i; \
for (i = 0; i < size; ++i) { \
char buf[4]; \
if (snprintf(buf, sizeof(buf), "%02x", (msg)[i]) != 2) { \
#define CLI_WRITENHEX(msg, size) \
do { \
unsigned i; \
for (i = 0; i < size; ++i) { \
char buf[4]; \
if (snprintf(buf, sizeof(buf), "%02x", (msg)[i]) != 2) { \
cli_warnmsg("vba_readdir_new: Failed to write nex data to output file\n"); \
ret = CL_EWRITE; \
goto done; \
} \
CLI_WRITEN(buf, 2); \
} \
ret = CL_EWRITE; \
goto done; \
} \
CLI_WRITEN(buf, 2); \
} \
} while (0)
#define CLI_WRITEN_MBCS(msg, size) \
do { \
char *utf8 = NULL; \
size_t utf8_size; \
if (size > 0) { \
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, codepage, &utf8, &utf8_size)) { \
CLI_WRITEN(utf8, utf8_size); \
free(utf8); \
utf8 = NULL; \
} else { \
cli_errmsg("cli_vba_readdir_new: failed to convert codepage %" PRIu16 " to UTF-8\n", codepage); \
CLI_WRITEN("<error decoding string>", 23); \
} \
} \
#define CLI_WRITEN_MBCS(msg, size) \
do { \
char *utf8 = NULL; \
size_t utf8_size; \
if (size > 0) { \
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, codepage, &utf8, &utf8_size)) { \
CLI_WRITEN(utf8, utf8_size); \
free(utf8); \
utf8 = NULL; \
} else { \
cli_errmsg("cli_vba_readdir_new: failed to convert codepage %" PRIu16 " to UTF-8\n", codepage); \
CLI_WRITEN("<error decoding string>", 23); \
} \
} \
} while (0)
#define CLI_WRITEN_UTF16LE(msg, size) \
do { \
char *utf8 = NULL; \
size_t utf8_size; \
if (size > 0) { \
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, CODEPAGE_UTF16_LE, &utf8, &utf8_size)) { \
CLI_WRITEN(utf8, utf8_size); \
free(utf8); \
utf8 = NULL; \
} else { \
cli_errmsg("cli_vba_readdir_new: failed to convert UTF16LE to UTF-8\n"); \
CLI_WRITEN("<error decoding string>", 23); \
} \
} \
#define CLI_WRITEN_UTF16LE(msg, size) \
do { \
char *utf8 = NULL; \
size_t utf8_size; \
if (size > 0) { \
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, CODEPAGE_UTF16_LE, &utf8, &utf8_size)) { \
CLI_WRITEN(utf8, utf8_size); \
free(utf8); \
utf8 = NULL; \
} else { \
cli_errmsg("cli_vba_readdir_new: failed to convert UTF16LE to UTF-8\n"); \
CLI_WRITEN("<error decoding string>", 23); \
} \
} \
} while (0)
CLI_WRITEN("REM VBA project extracted from Microsoft Office document\n\n", 58);
@ -473,7 +469,7 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
id = le16_to_host(*(uint16_t *) &data[data_offset]);
id = le16_to_host(*(uint16_t *)&data[data_offset]);
data_offset += 2;
if (data_offset + 4 > data_len) {
@ -481,7 +477,7 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size > data_len - data_offset) {
@ -490,7 +486,6 @@ cl_error_t
goto done;
}
switch (id) {
//MS-OVBA 2.3.4.2.1.1 PROJECTSYSKIND
case 0x0001: {
@ -499,7 +494,7 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint32_t sys_kind = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t sys_kind = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
CLI_WRITEN("REM PROJECTSYSKIND: ", 20);
switch (sys_kind) {
@ -517,10 +512,10 @@ cl_error_t
break;
default: {
char str_sys_kind[22];
int len = snprintf(str_sys_kind, sizeof(str_sys_kind), "Unknown (0x%x)", sys_kind);
int len = snprintf(str_sys_kind, sizeof(str_sys_kind), "Unknown (0x%x)", sys_kind);
str_sys_kind[sizeof(str_sys_kind) - 1] = '\0';
if (len > 0) {
CLI_WRITEN(str_sys_kind, (size_t) len);
CLI_WRITEN(str_sys_kind, (size_t)len);
}
break;
}
@ -535,13 +530,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint32_t lcid = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t lcid = le32_to_host(*(uint32_t *)&data[data_offset]);
char buf[64];
data_offset += 4;
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTLCID: 0x%08x\n", lcid);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTLCID: 0x%08x\n", lcid);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -552,13 +547,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint32_t lcid_invoke = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t lcid_invoke = le32_to_host(*(uint32_t *)&data[data_offset]);
char buf[64];
data_offset += 4;
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTLCIDINVOKE: 0x%08x\n", lcid_invoke);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTLCIDINVOKE: 0x%08x\n", lcid_invoke);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -569,13 +564,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
codepage = le16_to_host(*(uint16_t *) &data[data_offset]);
codepage = le16_to_host(*(uint16_t *)&data[data_offset]);
char buf[64];
data_offset += 2;
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTCODEPAGE: 0x%04x\n", codepage);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTCODEPAGE: 0x%04x\n", codepage);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -638,7 +633,7 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
id = le16_to_host(*(uint16_t *) &data[data_offset]);
id = le16_to_host(*(uint16_t *)&data[data_offset]);
if (id != 0x003d) {
cli_warnmsg("vba_readdir_new: PROJECTHELPFILEPATH is not followed by PROJECTHELPFILEPATH2\n");
CLI_WRITEN("REM WARNING: PROJECTHELPFILEPATH is not followed by PROJECTHELPFILEPATH2\n", 73);
@ -652,7 +647,7 @@ cl_error_t
goto done;
}
uint32_t size2;
size2 = le32_to_host(*(uint32_t *) &data[data_offset]);
size2 = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (data_offset + size > data_len) {
@ -669,8 +664,7 @@ cl_error_t
if (size != size2) {
CLI_WRITEN("REM WARNING: PROJECTHELPFILEPATH and PROJECTHELPFILEPATH2 record sizes differ\n", 78);
}
else {
} else {
if (memcmp(&data[projecthelpfilepath_offset], &data[data_offset], size) != 0) {
CLI_WRITEN("REM WARNING: PROJECTHELPFILEPATH and PROJECTHELPFILEPATH2 contents differ\n", 74);
}
@ -689,13 +683,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint32_t context = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t context = le32_to_host(*(uint32_t *)&data[data_offset]);
char buf[64];
data_offset += 4;
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTHELPCONTEXT: 0x%04x\n", context);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTHELPCONTEXT: 0x%04x\n", context);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -706,13 +700,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint32_t libflags = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t libflags = le32_to_host(*(uint32_t *)&data[data_offset]);
char buf[64];
data_offset += 4;
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTLIBFLAGS: 0x%04x\n", libflags);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTLIBFLAGS: 0x%04x\n", libflags);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -724,20 +718,20 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint32_t major = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t major = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (data_offset + 2 > data_len) {
cli_warnmsg("vba_readdir_new: PROJECTVERSION record stretches past the end of the file\n");
ret = CL_EREAD;
goto done;
}
uint16_t minor = le16_to_host(*(uint16_t *) &data[data_offset]);
uint16_t minor = le16_to_host(*(uint16_t *)&data[data_offset]);
data_offset += 2;
char buf[64];
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTVERSION: %u.%u\n", major, minor);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTVERSION: %u.%u\n", major, minor);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -748,13 +742,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint16_t modules = le16_to_host(*(uint16_t *) &data[data_offset]);
uint16_t modules = le16_to_host(*(uint16_t *)&data[data_offset]);
data_offset += 2;
char buf[64];
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTMODULES: %u\n", modules);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTMODULES: %u\n", modules);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -765,13 +759,13 @@ cl_error_t
ret = CL_EREAD;
goto done;
}
uint16_t cookie = le16_to_host(*(uint16_t *) &data[data_offset]);
uint16_t cookie = le16_to_host(*(uint16_t *)&data[data_offset]);
data_offset += 2;
char buf[64];
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTCOOKIE: 0x%04x\n", cookie);
int buf_length = snprintf(buf, sizeof(buf), "REM PROJECTCOOKIE: 0x%04x\n", cookie);
buf[sizeof(buf) - 1] = '\0';
if (buf_length > 0) {
CLI_WRITEN(buf, (size_t) buf_length);
CLI_WRITEN(buf, (size_t)buf_length);
}
break;
}
@ -781,9 +775,9 @@ cl_error_t
//MS-OVBA 2.3.4.2.3.2.1 MODULENAME
CLI_WRITEN("\n\nREM MODULENAME: ", 18);
if (size > 0) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, codepage, &mbcs_name, &mbcs_name_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, codepage, &mbcs_name, &mbcs_name_size)) {
CLI_WRITEN(mbcs_name, mbcs_name_size);
} else { \
} else {
cli_errmsg("cli_vba_readdir_new: failed to convert codepage %" PRIu16 " to UTF-8\n", codepage);
CLI_WRITEN("<error decoding string>", 23);
}
@ -791,7 +785,7 @@ cl_error_t
data_offset += size;
//MS-OVBA 2.3.4.2.3.2.2 MODULENAMEUNICODE
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x0047) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x0047) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULENAMEUNICODE (0x47) record, but got 0x%04x\n", id);
ret = CL_EREAD;
if (mbcs_name) {
@ -803,7 +797,7 @@ cl_error_t
cli_dbgmsg("Reading MODULENAMEUNICODE record\n");
data_offset += 2;
CLI_WRITEN("\nREM MODULENAMEUNICODE: ", 24);
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size > data_len - data_offset) {
@ -813,7 +807,7 @@ cl_error_t
}
if (size > 0) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, CODEPAGE_UTF16_LE, &utf16_name, &utf16_name_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, CODEPAGE_UTF16_LE, &utf16_name, &utf16_name_size)) {
CLI_WRITEN(utf16_name, utf16_name_size);
} else {
cli_errmsg("cli_vba_readdir_new: failed to convert UTF16LE to UTF-8\n");
@ -824,8 +818,7 @@ cl_error_t
if (mbcs_name && utf16_name &&
(mbcs_name_size != utf16_name_size ||
memcmp(mbcs_name, utf16_name, mbcs_name_size) != 0))
{
memcmp(mbcs_name, utf16_name, mbcs_name_size) != 0)) {
CLI_WRITEN("\nREM WARNING: MODULENAME and MODULENAMEUNICODE differ", 53);
}
@ -839,7 +832,7 @@ cl_error_t
}
//MS-OVBA 2.3.4.2.3.2.3 MODULESTREAMNAME
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x001a) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x001a) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULESTREAMNAME (0x1a) record, but got 0x%04x\n", id);
ret = CL_EREAD;
goto done;
@ -847,7 +840,7 @@ cl_error_t
cli_dbgmsg("Reading MODULESTREAMNAME record\n");
data_offset += 2;
CLI_WRITEN("\nREM MODULESTREAMNAME: ", 23);
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size > data_len - data_offset) {
@ -857,15 +850,15 @@ cl_error_t
}
if (size > 0) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, codepage, &mbcs_name, &mbcs_name_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, codepage, &mbcs_name, &mbcs_name_size)) {
CLI_WRITEN(mbcs_name, mbcs_name_size);
} else { \
} else {
cli_errmsg("cli_vba_readdir_new: failed to convert codepage %" PRIu16 " to UTF-8\n", codepage);
CLI_WRITEN("<error decoding string>", 23);
}
}
data_offset += size;
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x0032) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x0032) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULESTREAMNAMEUNICODE (0x32) record, but got 0x%04x\n", id);
ret = CL_EREAD;
if (mbcs_name) {
@ -877,11 +870,11 @@ cl_error_t
cli_dbgmsg("Reading MODULESTREAMNAMEUNICODE record\n");
data_offset += 2;
CLI_WRITEN("\nREM MODULESTREAMNAMEUNICODE: ", 30);
uint32_t module_stream_name_size = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t module_stream_name_size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
const unsigned char* module_stream_name = &data[data_offset];
const unsigned char *module_stream_name = &data[data_offset];
if (size > 0) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], module_stream_name_size, CODEPAGE_UTF16_LE, &utf16_name, &utf16_name_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], module_stream_name_size, CODEPAGE_UTF16_LE, &utf16_name, &utf16_name_size)) {
CLI_WRITEN(utf16_name, utf16_name_size);
} else {
cli_errmsg("cli_vba_readdir_new: failed to convert UTF16LE to UTF-8\n");
@ -892,10 +885,8 @@ cl_error_t
if (mbcs_name && utf16_name &&
(mbcs_name_size != utf16_name_size ||
memcmp(mbcs_name, utf16_name, mbcs_name_size) != 0))
{
memcmp(mbcs_name, utf16_name, mbcs_name_size) != 0)) {
CLI_WRITEN("\nREM WARNING: MODULESTREAMNAME and MODULESTREAMNAMEUNICODE differ", 65);
}
if (mbcs_name) {
@ -908,7 +899,7 @@ cl_error_t
}
//MS-OVBA 2.3.4.2.3.2.4 MODULEDOCSTRING
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x001c) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x001c) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEDOCSTRING (0x1c) record, but got 0x%04x\n", id);
ret = CL_EREAD;
goto done;
@ -916,7 +907,7 @@ cl_error_t
cli_dbgmsg("Reading MODULEDOCSTRING record\n");
data_offset += 2;
CLI_WRITEN("\nREM MODULEDOCSTRING: ", 22);
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size > data_len - data_offset) {
@ -926,15 +917,15 @@ cl_error_t
}
if (size > 0) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, codepage, &mbcs_name, &mbcs_name_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, codepage, &mbcs_name, &mbcs_name_size)) {
CLI_WRITEN(mbcs_name, mbcs_name_size);
} else { \
} else {
cli_errmsg("cli_vba_readdir_new: failed to convert codepage %" PRIu16 " to UTF-8\n", codepage);
CLI_WRITEN("<error decoding string>", 23);
}
}
data_offset += size;
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x0048) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x0048) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEDOCSTRINGUNICODE (0x32) record, but got 0x%04x\n", id);
ret = CL_EREAD;
if (mbcs_name) {
@ -946,7 +937,7 @@ cl_error_t
cli_dbgmsg("Reading MODULEDOCSTRINGUNICODE record\n");
data_offset += 2;
CLI_WRITEN("\nREM MODULEDOCSTRINGUNICODE: ", 29);
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size > data_len - data_offset) {
@ -956,7 +947,7 @@ cl_error_t
}
if (size > 0) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *) &data[data_offset], size, CODEPAGE_UTF16_LE, &utf16_name, &utf16_name_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)&data[data_offset], size, CODEPAGE_UTF16_LE, &utf16_name, &utf16_name_size)) {
CLI_WRITEN(utf16_name, utf16_name_size);
} else {
cli_errmsg("cli_vba_readdir_new: failed to convert UTF16LE to UTF-8\n");
@ -967,10 +958,8 @@ cl_error_t
if (mbcs_name && utf16_name &&
(mbcs_name_size != utf16_name_size ||
memcmp(mbcs_name, utf16_name, mbcs_name_size) != 0))
{
memcmp(mbcs_name, utf16_name, mbcs_name_size) != 0)) {
CLI_WRITEN("\nREM WARNING: MODULEDOCSTRING and MODULEDOCSTRINGUNICODE differ", 63);
}
if (mbcs_name) {
@ -983,81 +972,81 @@ cl_error_t
}
//MS-OVBA 2.3.4.2.3.2.5 MODULEOFFSET
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x0031) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x0031) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEOFFSET (0x31) record, but got 0x%04x\n", id);
ret = CL_EREAD;
goto done;
}
cli_dbgmsg("Reading MODULEOFFSET record\n");
data_offset += 2;
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size != 4) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEOFFSET record size");
ret = CL_EREAD;
goto done;
}
uint32_t module_offset = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t module_offset = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
char buffer[64];
int buffer_size = snprintf(buffer, sizeof(buffer), "\nREM MODULEOFFSET: 0x%08x", module_offset);
if (buffer_size > 0) {
CLI_WRITEN(buffer, (size_t) buffer_size);
CLI_WRITEN(buffer, (size_t)buffer_size);
}
//MS-OVBA 2.3.4.2.3.2.6 MODULEHELPCONTEXT
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x001e) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x001e) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEHELPCONTEXT (0x1e) record, but got 0x%04x\n", id);
ret = CL_EREAD;
goto done;
}
cli_dbgmsg("Reading MODULEHELPCONTEXT record\n");
data_offset += 2;
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size != 4) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEHELPCONTEXT record size");
ret = CL_EREAD;
goto done;
}
uint32_t help_context = le32_to_host(*(uint32_t *) &data[data_offset]);
uint32_t help_context = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
buffer_size = snprintf(buffer, sizeof(buffer), "\nREM MODULEHELPCONTEXT: 0x%08x", help_context);
if (buffer_size > 0) {
CLI_WRITEN(buffer, (size_t) buffer_size);
CLI_WRITEN(buffer, (size_t)buffer_size);
}
//MS-OVBA 2.3.4.2.3.2.7 MODULECOOKIE
if ((id = le16_to_host(*(uint16_t *) &data[data_offset])) != 0x002c) {
if ((id = le16_to_host(*(uint16_t *)&data[data_offset])) != 0x002c) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULECOOKIE (0x2c) record, but got 0x%04x\n", id);
ret = CL_EREAD;
goto done;
}
cli_dbgmsg("Reading MODULECOOKIE record\n");
data_offset += 2;
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size != 2) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULECOOKIE record size");
ret = CL_EREAD;
goto done;
}
uint16_t cookie = le32_to_host(*(uint16_t *) &data[data_offset]);
uint16_t cookie = le32_to_host(*(uint16_t *)&data[data_offset]);
data_offset += 2;
buffer_size = snprintf(buffer, sizeof(buffer), "\nREM MODULECOOKIE: 0x%04x", cookie);
if (buffer_size > 0) {
CLI_WRITEN(buffer, (size_t) buffer_size);
CLI_WRITEN(buffer, (size_t)buffer_size);
}
//MS-OVBA 2.3.4.2.3.2.8 MODULETYPE
id = le16_to_host(*(uint16_t *) &data[data_offset]);
id = le16_to_host(*(uint16_t *)&data[data_offset]);
if (id != 0x0021 && id != 0x0022) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULETYPE (0x21/0x22) record, but got 0x%04x\n", id);
ret = CL_EREAD;
goto done;
}
data_offset += 2;
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size != 0) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULETYPE record size");
@ -1066,16 +1055,15 @@ cl_error_t
}
if (id == 0x21) {
CLI_WRITEN("\nREM MODULETYPE: Procedural", 27);
}
else {
} else {
CLI_WRITEN("\nREM MODULETYPE: Class", 22);
}
//MS-OVBA 2.3.4.2.3.2.9 MODULEREADONLY
id = le16_to_host(*(uint16_t *) &data[data_offset]);
id = le16_to_host(*(uint16_t *)&data[data_offset]);
if (id == 0x0025) {
data_offset += 2;
size = le16_to_host(*(uint16_t *) &data[data_offset]);
size = le16_to_host(*(uint16_t *)&data[data_offset]);
data_offset += 4;
if (size != 0) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEREADONLY record size");
@ -1083,13 +1071,13 @@ cl_error_t
goto done;
}
CLI_WRITEN("\nREM MODULEREADONLY", 19);
id = le16_to_host(*(uint16_t *) &data[data_offset]);
id = le16_to_host(*(uint16_t *)&data[data_offset]);
}
//MS-OVBA 2.3.4.2.3.2.10 MODULEPRIVATE
if (id == 0x0028) {
data_offset += 2;
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size != 0) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULEPRIVATE record size");
@ -1097,12 +1085,12 @@ cl_error_t
goto done;
}
CLI_WRITEN("\nREM MODULEPRIVATE", 18);
id = le16_to_host(*(uint16_t *) &data[data_offset]);
id = le16_to_host(*(uint16_t *)&data[data_offset]);
}
//Terminator
if (id != 0x002b) {
size = le32_to_host(*(uint32_t *) &data[data_offset]);
size = le32_to_host(*(uint32_t *)&data[data_offset]);
data_offset += 4;
if (size != 0) {
cli_dbgmsg("cli_vba_readdir_new: Expected MODULETERMINATOR record size");
@ -1113,14 +1101,14 @@ cl_error_t
CLI_WRITEN("\nREM ##################################################\n", 56);
stream_name = cli_ole2_get_property_name2((const char *) module_stream_name, (int) (module_stream_name_size + 2));
stream_name = cli_ole2_get_property_name2((const char *)module_stream_name, (int)(module_stream_name_size + 2));
char *module_hash;
uint32_t module_hashcnt;
if (stream_name == NULL) {
ret = CL_EMEM;
goto done;
}
if (uniq_get(U, stream_name, (uint32_t) strlen(stream_name), &module_hash, &module_hashcnt) != CL_SUCCESS) {
if (uniq_get(U, stream_name, (uint32_t)strlen(stream_name), &module_hash, &module_hashcnt) != CL_SUCCESS) {
cli_dbgmsg("cli_vba_readdir_new: Cannot find module stream %s\n", stream_name);
ret = CL_EOPEN;
goto done;
@ -1147,15 +1135,14 @@ cl_error_t
close(module_fd);
if (CL_SUCCESS == cli_codepage_to_utf8((char *) module_data, module_data_size, codepage, (char **) &module_data_utf8, &module_data_utf8_size)) {
if (CL_SUCCESS == cli_codepage_to_utf8((char *)module_data, module_data_size, codepage, (char **)&module_data_utf8, &module_data_utf8_size)) {
module_data_utf8_size = vba_normalize(module_data_utf8, module_data_utf8_size);
CLI_WRITEN(module_data_utf8, module_data_utf8_size);
module_stream_found = 1;
free(module_data_utf8);
module_data_utf8 = NULL;
}
else {
} else {
CLI_WRITEN("\n<Error decoding module data>\n", 30);
cli_dbgmsg("cli_vba_readdir_new: Failed to decode VBA module content from codepage %" PRIu16 " to UTF8\n", codepage);
}
@ -1168,7 +1155,7 @@ cl_error_t
if (!module_stream_found) {
cli_dbgmsg("cli_vba_readdir_new: Cannot find module stream %s\n", stream_name);
}
free((void *) stream_name);
free((void *)stream_name);
stream_name = NULL;
break;
@ -1193,10 +1180,10 @@ done:
close(fd);
}
if (data) {
free((void *) data);
free((void *)data);
}
if (stream_name) {
free((void *) stream_name);
free((void *)stream_name);
}
if (tempfile) {
free(tempfile);
@ -1213,11 +1200,11 @@ done:
free(mbcs_name);
mbcs_name = NULL;
}
if (module_data){
if (module_data) {
free(module_data);
module_data = NULL;
}
if (module_data_utf8){
if (module_data_utf8) {
free(module_data_utf8);
module_data_utf8 = NULL;
}

View file

@ -40,7 +40,7 @@ typedef struct vba_project_tag {
} vba_project_t;
vba_project_t *cli_vba_readdir(const char *dir, struct uniq *U, uint32_t which);
cl_error_t cli_vba_readdir_new(cli_ctx* ctx, const char *dir, struct uniq *U, const char *hash, uint32_t which, int *tempfd);
cl_error_t cli_vba_readdir_new(cli_ctx *ctx, const char *dir, struct uniq *U, const char *hash, uint32_t which, int *tempfd);
vba_project_t *cli_wm_readdir(int fd);
void cli_free_vba_project(vba_project_t *vba_project);

View file

@ -168,18 +168,18 @@ static void printTime(double seconds)
fprintf(stdout, "%2.0fm %02.0fs", trunc(seconds / 60), trunc(fmod(seconds, 60.0)));
} else {
fprintf(stdout, "%6.1fs", seconds);
}
}
}
static void printBytes(curl_off_t bytes, int bPad)
{
if (bytes >= (1024 * 1024)) {
const char *format = bPad ? "%7.02fMiB" : "%.02fMiB";
double megabytes = bytes / (double)(1024 * 1024);
double megabytes = bytes / (double)(1024 * 1024);
fprintf(stdout, format, megabytes);
} else if (bytes >= 1024) {
const char *format = bPad ? "%7.02fKiB" : "%.02fKiB";
double kilobytes = bytes / (double)(1024);
double kilobytes = bytes / (double)(1024);
fprintf(stdout, format, kilobytes);
} else {
const char *format = bPad ? "%9" CURL_FORMAT_CURL_OFF_T "B" : "%" CURL_FORMAT_CURL_OFF_T "B";
@ -1112,8 +1112,8 @@ static fc_error_t getcvd(
if (cvd->version < remoteVersion) {
if (cvd->version == remoteVersion - 1) {
logg("*The %s database downloaded from %s is one version older than advertised in the DNS TXT record.\n",
cvdfile,
server);
cvdfile,
server);
/*
* Tolerate an off-by-one version mismatch.
@ -1121,11 +1121,10 @@ static fc_error_t getcvd(
*/
status = FC_SUCCESS;
goto done;
}
else {
} else {
logg("!The %s database downloaded from %s is more than one version older than the version advertised in the DNS TXT record.\n",
cvdfile,
server);
cvdfile,
server);
status = FC_EMIRRORNOTSYNC;
goto done;
}

View file

@ -1092,7 +1092,7 @@ static int sigtool_scandir(const char *dirname, int hex_output)
char *dir;
int ret = CL_CLEAN, desc;
cli_ctx *ctx;
int has_vba = 0, has_xlm = 0;
int has_vba = 0, has_xlm = 0;
fname = NULL;
if ((dd = opendir(dirname)) != NULL) {

View file

@ -129,17 +129,17 @@ static void runtest(const char *file, uint64_t expected, int fail, int nojit,
cli_bytecode_context_setfuncid(ctx, &bc, 0);
rc = cli_bytecode_run(&bcs, &bc, ctx);
ck_assert_msg(rc == fail, "cli_bytecode_run failed, expected: %u, have: %u\n",
fail, rc);
fail, rc);
if (rc == CL_SUCCESS) {
v = cli_bytecode_context_getresult_int(ctx);
ck_assert_msg(v == expected, "Invalid return value from bytecode run, expected: %llx, have: %llx\n",
expected, v);
expected, v);
}
if (infile && expectedvirname) {
ck_assert_msg(ctx->virname &&
!strcmp(ctx->virname, expectedvirname),
"Invalid virname, expected: %s\n", expectedvirname);
!strcmp(ctx->virname, expectedvirname),
"Invalid virname, expected: %s\n", expectedvirname);
}
cli_bytecode_context_destroy(ctx);
if (map)
@ -494,14 +494,14 @@ static void runload(const char *dbname, struct cl_engine *engine, unsigned signo
rc = cl_load(str, engine, &signo, CL_DB_STDOPT);
ck_assert_msg(rc == CL_SUCCESS, "failed to load %s: %s\n",
dbname, cl_strerror(rc));
dbname, cl_strerror(rc));
ck_assert_msg(signo == signoexp, "different number of signatures loaded, expected %u, got %u\n",
signoexp, signo);
signoexp, signo);
free(str);
rc = cl_engine_compile(engine);
ck_assert_msg(rc == CL_SUCCESS, "failed to load %s: %s\n",
dbname, cl_strerror(rc));
dbname, cl_strerror(rc));
}
START_TEST(test_load_bytecode_jit)

View file

@ -53,7 +53,6 @@
#include "libclamav/clamav.h"
#include "libclamav/version.h"
static int sockd;
#define SOCKET "clamd-test.socket"
static void conn_setup_mayfail(int may)
@ -131,13 +130,13 @@ static void commands_setup(void)
fd = open(ACCDENIED, O_CREAT | O_WRONLY, S_IWUSR);
ck_assert_msg(fd != -1,
"Failed to create file for access denied tests: %s\n", strerror(errno));
"Failed to create file for access denied tests: %s\n", strerror(errno));
ck_assert_msg(fchmod(fd, S_IWUSR) != -1,
"Failed to chmod: %s\n", strerror(errno));
"Failed to chmod: %s\n", strerror(errno));
/* must not be empty file */
ck_assert_msg((size_t)write(fd, nonempty, strlen(nonempty)) == strlen(nonempty),
"Failed to write into testfile: %s\n", strerror(errno));
"Failed to write into testfile: %s\n", strerror(errno));
close(fd);
/* skip access denied tests when run as root, as root will ignore
@ -244,7 +243,7 @@ static void test_command(const char *cmd, size_t len, const char *extra, const c
recvdata = recvfull(sockd, &len);
ck_assert_msg(len == expect_len, "Reply has wrong size: %lu, expected %lu, reply: %s, expected: %s\n",
len, expect_len, recvdata, expect);
len, expect_len, recvdata, expect);
rc = memcmp(recvdata, expect, expect_len);
ck_assert_msg(!rc, "Wrong reply for command %s: |%s|, expected: |%s|\n", cmd, recvdata, expect);
@ -330,7 +329,7 @@ START_TEST(test_stats)
recvdata = recvfull(sockd, &len);
ck_assert_msg(len > strlen(STATS_REPLY), "Reply has wrong size: %lu, minimum %lu, reply: %s\n",
len, strlen(STATS_REPLY), recvdata);
len, strlen(STATS_REPLY), recvdata);
if (len > strlen(STATS_REPLY))
len = strlen(STATS_REPLY);
@ -383,7 +382,7 @@ START_TEST(test_instream)
expect_len = strlen(EXPECT_INSTREAM);
ck_assert_msg(len == expect_len, "Reply has wrong size: %lu, expected %lu, reply: %s\n",
len, expect_len, recvdata);
len, expect_len, recvdata);
rc = memcmp(recvdata, EXPECT_INSTREAM, expect_len);
ck_assert_msg(!rc, "Wrong reply for command INSTREAM: |%s|, expected: |%s|\n", recvdata, EXPECT_INSTREAM);
@ -445,7 +444,7 @@ static void tst_fildes(const char *cmd, size_t len, int fd,
conn_setup();
ck_assert_msg(sendmsg_fd(sockd, cmd, len, fd, singlemsg) != -1,
"Failed to sendmsg: %s\n", strerror(errno));
"Failed to sendmsg: %s\n", strerror(errno));
if (closefd)
close(fd);
@ -460,7 +459,7 @@ static void tst_fildes(const char *cmd, size_t len, int fd,
len -= p - recvdata;
ck_assert_msg(len == expect_len, "Reply has wrong size: %lu, expected %lu, reply: %s, expected: %s\n",
len, expect_len, p, expect);
len, expect_len, p, expect);
rc = memcmp(p, expect, expect_len);
ck_assert_msg(!rc, "Wrong reply for command %s: |%s|, expected: |%s|\n", cmd, p, expect);
@ -569,12 +568,12 @@ START_TEST(test_fildes_unwanted)
/* send a 'zVERSION\0' including the ancillary data.
* The \0 is from the extra char needed when sending ancillary data */
ck_assert_msg(sendmsg_fd(sockd, "zIDSESSION", strlen("zIDSESSION"), dummyfd, 1) != -1,
"sendmsg failed: %s\n", strerror(errno));
"sendmsg failed: %s\n", strerror(errno));
recvdata = recvfull(sockd, &len);
ck_assert_msg(!strcmp(recvdata, "1: PROTOCOL ERROR: ancillary data sent without FILDES. ERROR"),
"Wrong reply: %s\n", recvdata);
"Wrong reply: %s\n", recvdata);
free(recvdata);
close(dummyfd);
@ -592,11 +591,11 @@ START_TEST(test_idsession_stress)
conn_setup();
ck_assert_msg(send(sockd, "zIDSESSION", sizeof("zIDSESSION"), 0) == sizeof("zIDSESSION"),
"send() failed: %s\n", strerror(errno));
"send() failed: %s\n", strerror(errno));
for (i = 0; i < 1024; i++) {
snprintf(buf, sizeof(buf), "%u", (unsigned)(i + 1));
ck_assert_msg(send(sockd, "zVERSION", sizeof("zVERSION"), 0) == sizeof("zVERSION"),
"send failed: %s\n", strerror(errno));
"send failed: %s\n", strerror(errno));
data = recvpartial(sockd, &len, 1);
p = strchr(data, ':');
ck_assert_msg(!!p, "wrong VERSION reply (%u): %s\n", i, data);
@ -624,7 +623,7 @@ START_TEST(test_connections)
int *sock;
int nf, maxfd = 0;
ck_assert_msg(getrlimit(RLIMIT_NOFILE, &rlim) != -1,
"Failed to get RLIMIT_NOFILE: %s\n", strerror(errno));
"Failed to get RLIMIT_NOFILE: %s\n", strerror(errno));
nf = rlim.rlim_cur - 5;
sock = malloc(sizeof(int) * nf);
@ -698,7 +697,7 @@ START_TEST(test_stream)
"send failed: %s\n", strerror(errno));
recvdata = recvpartial(sockd, &len, 1);
ck_assert_msg(sscanf(recvdata, "PORT %u\n", &port) == 1,
"Wrong stream reply: %s\n", recvdata);
"Wrong stream reply: %s\n", recvdata);
free(recvdata);
streamsd = conn_tcp(port);
@ -707,7 +706,7 @@ START_TEST(test_stream)
nread = read(infd, buf, sizeof(buf));
if (nread > 0)
ck_assert_msg(send(streamsd, buf, nread, 0) == nread,
"send failed: %s\n", strerror(errno));
"send failed: %s\n", strerror(errno));
} while (nread > 0 || (nread == -1 && errno == EINTR));
ck_assert_msg(nread != -1, "read failed: %s\n", strerror(errno));
close(infd);
@ -715,7 +714,7 @@ START_TEST(test_stream)
recvdata = recvfull(sockd, &len);
ck_assert_msg(!strcmp(recvdata, "stream: ClamAV-Test-File.UNOFFICIAL FOUND"),
"Wrong reply: %s\n", recvdata);
"Wrong reply: %s\n", recvdata);
free(recvdata);
conn_teardown();
@ -801,9 +800,9 @@ static void test_idsession_commands(int split, int instream)
ck_assert_msg(id <= j, "ID too big: %u, max: %u\n", id, j);
q += 2;
ck_assert_msg(!strcmp(q, replies[id - 1]),
"Wrong ID reply for ID %u: %s, expected %s\n",
id,
q, replies[id - 1]);
"Wrong ID reply for ID %u: %s, expected %s\n",
id,
q, replies[id - 1]);
p = q + strlen(q) + 1;
}
}
@ -816,15 +815,15 @@ START_TEST(test_idsession)
{
conn_setup();
ck_assert_msg((size_t)send(sockd, ID_CMD, sizeof(ID_CMD), 0) == sizeof(ID_CMD),
"send() failed: %s\n", strerror(errno));
"send() failed: %s\n", strerror(errno));
test_idsession_commands(0, 0);
conn_setup();
ck_assert_msg((size_t)send(sockd, ID_CMD, sizeof(ID_CMD), 0) == sizeof(ID_CMD),
"send() failed: %s\n", strerror(errno));
"send() failed: %s\n", strerror(errno));
test_idsession_commands(1, 0);
conn_setup();
ck_assert_msg((size_t)send(sockd, ID_CMD, sizeof(ID_CMD), 0) == sizeof(ID_CMD),
"send() failed: %s\n", strerror(errno));
"send() failed: %s\n", strerror(errno));
test_idsession_commands(0, 1);
}
END_TEST

View file

@ -287,8 +287,8 @@ START_TEST(regex_list_match_test)
ck_assert_msg(is_regex_ok(&matcher), "is_regex_ok");
realurl = cli_strdup(rtest->realurl);
rc = regex_list_match(&matcher, realurl, rtest->displayurl, NULL, 1, &info, 1);
realurl = cli_strdup(rtest->realurl);
rc = regex_list_match(&matcher, realurl, rtest->displayurl, NULL, 1, &info, 1);
ck_assert_msg(rc == rtest->result, "regex_list_match");
/* regex_list_match is not supposed to modify realurl in this case */
ck_assert_msg(!strcmp(realurl, rtest->realurl), "realurl altered");

View file

@ -85,12 +85,12 @@ START_TEST(test_unescape_unicode)
str = cli_unescape("%u00a2%u007f%u0080%u07ff%u0800%ue000");
ck_assert_msg(str && !strcmp(str, "\xc2\xa2\x7f\xc2\x80\xdf\xbf\xe0\xa0\x80\xee\x80\x80"),
"cli_unescape utf-8 test");
"cli_unescape utf-8 test");
free(str);
str = cli_unescape("%%u123%u12%u1%u%u1234");
ck_assert_msg(str && !strcmp(str, "%%u123%u12%u1%u\xe1\x88\xb4"),
"cli_unescape unicode truncated");
"cli_unescape unicode truncated");
free(str);
}
@ -159,7 +159,7 @@ START_TEST(hex2str)
r = cli_hex2str(inp1);
ck_assert_msg(!!r, "cli_hex2str NULL");
ck_assert_msg(!memcmp(r, out1, sizeof(out1) - 1),
"cli_hex2str invalid output");
"cli_hex2str invalid output");
free(r);
r = cli_hex2str(inp2);
@ -202,10 +202,10 @@ START_TEST(test_base64)
*ret2 = '\0';
len = ret2 - buf;
ck_assert_msg(len == test->len, "invalid base64 decoded length: %u expected %u (%s)\n",
len, test->len, buf);
len, test->len, buf);
ck_assert_msg(!memcmp(buf, test->decoded, test->len),
"invalid base64 decoded data: %s, expected:%s\n",
buf, test->decoded);
"invalid base64 decoded data: %s, expected:%s\n",
buf, test->decoded);
messageDestroy(m);
}
END_TEST
@ -251,7 +251,6 @@ START_TEST(test_u16_u8)
}
END_TEST
Suite *test_str_suite(void)
{
Suite *s = suite_create("str");

View file

@ -66,12 +66,11 @@ const lt_dlinfo *lt_dlgetinfo(lt_dlhandle handle)
return &dlinfo;
}
int lt_dlclose (lt_dlhandle handle)
int lt_dlclose(lt_dlhandle handle)
{
int ret;
ret = FreeLibrary(handle);
if (0 == ret)
{
if (0 == ret) {
lasterr = GetLastError();
return 1;
}