Primarily this commit fixes an issue with the size of the parameters
passed to cli_checklimits(). The parameters were "unsigned long", which
varies in size depending on platform.
I've switched them to uint64_t / u64.
While working on this, I observed some concerning warnigns on Windows,
and some less serious ones, primarily regarding inconsistencies with
`const` parameters.
Finally, in `scanmem.c`, there is a warning regarding use of `wchar_t *`
with `GetModuleFileNameEx()` instead of `GetModuleFileNameExW()`.
This made me realize this code assumes we're not defining `UNICODE`,
which would have such macros use the 'A' variant.
I have fixed it the best I can, although I'm still a little
uncomfortable with some of this code that uses `char` or `wchar_t`
instead of TCHAR.
I also remove the `if (GetModuleFileNameEx) {` conditional, because this
macro/function will always be defined. The original code was checking a
function pointer, and so this was a bug when integrating into ClamAV.
Regarding the changes to `rijndael.c`, I found that this module assumes
`unsigned long` == 32bits. It does not.
I have corrected it to use `uint32_t`.
| ... | ... |
@@ -56,7 +56,8 @@ int tcpserver(int **lsockets, unsigned int *nlsockets, char *ipaddr, const struc |
| 56 | 56 |
int *sockets; |
| 57 | 57 |
int sockfd = 0, backlog; |
| 58 | 58 |
int *t; |
| 59 |
- char *estr, port[10]; |
|
| 59 |
+ const char *estr = NULL; |
|
| 60 |
+ char port[10]; |
|
| 60 | 61 |
int yes = 1; |
| 61 | 62 |
int res; |
| 62 | 63 |
unsigned int i = 0; |
| ... | ... |
@@ -267,7 +267,7 @@ int thrmgr_printstats(int f, char term) |
| 267 | 267 |
const struct cl_engine **s; |
| 268 | 268 |
/* new engine */ |
| 269 | 269 |
++seen_cnt; |
| 270 |
- s = realloc(seen, seen_cnt * sizeof(*seen)); |
|
| 270 |
+ s = realloc((void *)seen, seen_cnt * sizeof(*seen)); |
|
| 271 | 271 |
if (!s) {
|
| 272 | 272 |
error_flag = 1; |
| 273 | 273 |
break; |
| ... | ... |
@@ -285,7 +285,7 @@ int thrmgr_printstats(int f, char term) |
| 285 | 285 |
} |
| 286 | 286 |
mdprintf(f, "\n"); |
| 287 | 287 |
} |
| 288 |
- free(seen); |
|
| 288 |
+ free((void *)seen); |
|
| 289 | 289 |
#ifdef HAVE_MALLINFO |
| 290 | 290 |
{
|
| 291 | 291 |
struct mallinfo inf = mallinfo(); |
| ... | ... |
@@ -183,7 +183,7 @@ static WINDOW *stats_window = NULL; |
| 183 | 183 |
static WINDOW *status_bar_window = NULL; |
| 184 | 184 |
static WINDOW *mem_window = NULL; |
| 185 | 185 |
|
| 186 |
-static const char *status_bar_keys[10]; |
|
| 186 |
+static char *status_bar_keys[10]; |
|
| 187 | 187 |
static unsigned maxy = 0, maxx = 0; |
| 188 | 188 |
static char *queue_header = NULL; |
| 189 | 189 |
static char *multi_queue_header = NULL; |
| ... | ... |
@@ -227,47 +227,47 @@ int walkmodules_th(proc_callback callback, void *data, struct mem_info *info) |
| 227 | 227 |
} |
| 228 | 228 |
|
| 229 | 229 |
/* Check and transform non ANSI filenames to ANSI using altnames */ |
| 230 |
- if (GetModuleFileNameEx) {
|
|
| 231 |
- HANDLE hFile = CreateFile( |
|
| 232 |
- me32.szExePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
|
| 233 |
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); |
|
| 234 |
- |
|
| 235 |
- if (hFile == INVALID_HANDLE_VALUE) {
|
|
| 236 |
- DWORD err = GetLastError(); |
|
| 237 |
- wchar_t name[MAX_PATH + 1]; |
|
| 238 |
- char *converted = NULL; |
|
| 239 |
- HANDLE p; |
|
| 240 |
- |
|
| 241 |
- if (err == ERROR_BAD_NETPATH) {
|
|
| 242 |
- logg(LOGG_WARNING, "Warning scanning files on non-ansi network paths is not " |
|
| 243 |
- "supported\n"); |
|
| 244 |
- logg(LOGG_WARNING, "File: %s\n", me32.szExePath); |
|
| 245 |
- continue; |
|
| 246 |
- } |
|
| 247 |
- |
|
| 248 |
- if ((err != ERROR_INVALID_NAME) && (err != ERROR_PATH_NOT_FOUND)) {
|
|
| 249 |
- logg(LOGG_WARNING, "Expected ERROR_INVALID_NAME/ERROR_PATH_NOT_FOUND but got %d\n", |
|
| 250 |
- err); |
|
| 251 |
- continue; |
|
| 252 |
- } |
|
| 253 |
- |
|
| 254 |
- p = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, |
|
| 255 |
- ps.th32ProcessID); |
|
| 256 |
- if (!GetModuleFileNameEx(p, NULL, name, MAX_PATH)) {
|
|
| 257 |
- logg(LOGG_WARNING, "GetModuleFileNameExW() failed %d\n", GetLastError()); |
|
| 258 |
- CloseHandle(p); |
|
| 259 |
- continue; |
|
| 260 |
- } |
|
| 230 |
+ HANDLE hFile = CreateFileA( |
|
| 231 |
+ me32.szExePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
|
| 232 |
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); |
|
| 233 |
+ |
|
| 234 |
+ if (hFile == INVALID_HANDLE_VALUE) {
|
|
| 235 |
+ DWORD err = GetLastError(); |
|
| 236 |
+ wchar_t nameW[MAX_PATH + 1]; |
|
| 237 |
+ char *converted = NULL; |
|
| 238 |
+ HANDLE p; |
|
| 239 |
+ |
|
| 240 |
+ if (err == ERROR_BAD_NETPATH) {
|
|
| 241 |
+ logg(LOGG_WARNING, "Warning scanning files on non-ansi network paths is not " |
|
| 242 |
+ "supported\n"); |
|
| 243 |
+ logg(LOGG_WARNING, "File: %s\n", me32.szExePath); |
|
| 244 |
+ continue; |
|
| 245 |
+ } |
|
| 246 |
+ |
|
| 247 |
+ if ((err != ERROR_INVALID_NAME) && (err != ERROR_PATH_NOT_FOUND)) {
|
|
| 248 |
+ logg(LOGG_WARNING, "Expected ERROR_INVALID_NAME/ERROR_PATH_NOT_FOUND but got %d\n", |
|
| 249 |
+ err); |
|
| 250 |
+ continue; |
|
| 251 |
+ } |
|
| 252 |
+ |
|
| 253 |
+ p = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, |
|
| 254 |
+ ps.th32ProcessID); |
|
| 255 |
+ |
|
| 256 |
+ if (!GetModuleFileNameExW(p, NULL, nameW, MAX_PATH)) {
|
|
| 257 |
+ logg(LOGG_WARNING, "GetModuleFileNameExW() failed %d\n", GetLastError()); |
|
| 261 | 258 |
CloseHandle(p); |
| 259 |
+ continue; |
|
| 260 |
+ } |
|
| 261 |
+ CloseHandle(p); |
|
| 262 | 262 |
|
| 263 |
- if (!(converted = getaltpath(name))) {
|
|
| 264 |
- logg(LOGG_WARNING, "Cannot map filename to ANSI codepage\n"); |
|
| 265 |
- continue; |
|
| 266 |
- } |
|
| 267 |
- strcpy(me32.szExePath, converted); |
|
| 268 |
- free(converted); |
|
| 269 |
- } else |
|
| 270 |
- CloseHandle(hFile); |
|
| 263 |
+ if (!(converted = getaltpath(nameW))) {
|
|
| 264 |
+ logg(LOGG_WARNING, "Cannot map filename to ANSI codepage\n"); |
|
| 265 |
+ continue; |
|
| 266 |
+ } |
|
| 267 |
+ strcpy(me32.szExePath, converted); |
|
| 268 |
+ free(converted); |
|
| 269 |
+ } else {
|
|
| 270 |
+ CloseHandle(hFile); |
|
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 | 273 |
do |
| ... | ... |
@@ -319,8 +319,8 @@ int walkmodules_psapi(proc_callback callback, void *data, struct mem_info *info) |
| 319 | 319 |
continue; |
| 320 | 320 |
} |
| 321 | 321 |
|
| 322 |
- if (!GetModuleBaseName(hProc, mods[0], ps.szExeFile, |
|
| 323 |
- MAX_PATH - 1)) {
|
|
| 322 |
+ if (!GetModuleBaseNameA(hProc, mods[0], ps.szExeFile, |
|
| 323 |
+ MAX_PATH - 1)) {
|
|
| 324 | 324 |
CloseHandle(hProc); |
| 325 | 325 |
continue; |
| 326 | 326 |
} |
| ... | ... |
@@ -515,8 +515,8 @@ int dump_pe(const char *filename, PROCESSENTRY32 ProcStruct, |
| 515 | 515 |
/* PE Realignment */ |
| 516 | 516 |
align_pe(buffer, me32.modBaseSize); |
| 517 | 517 |
|
| 518 |
- hFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
|
| 519 |
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|
| 518 |
+ hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
|
| 519 |
+ CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|
| 520 | 520 |
if (hFile == INVALID_HANDLE_VALUE) {
|
| 521 | 521 |
logg(LOGG_INFO, "Error creating %s\n", filename); |
| 522 | 522 |
free(buffer); |
| ... | ... |
@@ -598,7 +598,7 @@ int scanmem_cb(PROCESSENTRY32 ProcStruct, MODULEENTRY32 me32, void *data, struct |
| 598 | 598 |
snprintf(expandmodule, MAX_PATH - 1, "%%SystemRoot%%\\%s", |
| 599 | 599 |
&me32.szExePath[12]); |
| 600 | 600 |
expandmodule[MAX_PATH - 1] = 0; |
| 601 |
- ExpandEnvironmentStrings(expandmodule, modulename, MAX_PATH - 1); |
|
| 601 |
+ ExpandEnvironmentStringsA(expandmodule, modulename, MAX_PATH - 1); |
|
| 602 | 602 |
modulename[MAX_PATH - 1] = 0; |
| 603 | 603 |
} |
| 604 | 604 |
|
| ... | ... |
@@ -630,7 +630,7 @@ int scanmem_cb(PROCESSENTRY32 ProcStruct, MODULEENTRY32 me32, void *data, struct |
| 630 | 630 |
if ((fd = dump_pe(dumped, ProcStruct, me32)) > 0) {
|
| 631 | 631 |
close(fd); |
| 632 | 632 |
scan_data->res = scanfile(dumped, scan_data, info); |
| 633 |
- DeleteFile(dumped); |
|
| 633 |
+ DeleteFileA(dumped); |
|
| 634 | 634 |
} |
| 635 | 635 |
free(dumped); |
| 636 | 636 |
} |
| ... | ... |
@@ -667,8 +667,8 @@ int scanmem(struct mem_info *info) |
| 667 | 667 |
data.processes = 0; |
| 668 | 668 |
data.modules = 0; |
| 669 | 669 |
|
| 670 |
- HMODULE psapi_ok = LoadLibrary("psapi.dll");
|
|
| 671 |
- HMODULE k32_ok = LoadLibrary("kernel32.dll");
|
|
| 670 |
+ HMODULE psapi_ok = LoadLibraryA("psapi.dll");
|
|
| 671 |
+ HMODULE k32_ok = LoadLibraryA("kernel32.dll");
|
|
| 672 | 672 |
|
| 673 | 673 |
if (!(psapi_ok || k32_ok)) {
|
| 674 | 674 |
logg(LOGG_INFO, " *** Memory Scanning is not supported on this OS ***\n\n"); |
| ... | ... |
@@ -49,7 +49,7 @@ cl_error_t cert_store_load(X509 **trusted_certs, size_t trusted_cert_count) |
| 49 | 49 |
cert_store_t *store = NULL; |
| 50 | 50 |
bool locked = false; |
| 51 | 51 |
|
| 52 |
- hStore = CertOpenSystemStoreA(NULL, "ROOT"); |
|
| 52 |
+ hStore = CertOpenSystemStoreA(0, "ROOT"); |
|
| 53 | 53 |
if (NULL == hStore) {
|
| 54 | 54 |
mprintf(LOGG_ERROR, "Failed to open system certificate store.\n"); |
| 55 | 55 |
goto done; |
| ... | ... |
@@ -924,7 +924,7 @@ static int dmg_stripe_bzip(cli_ctx *ctx, int fd, uint32_t index, struct dmg_mish |
| 924 | 924 |
break; |
| 925 | 925 |
} |
| 926 | 926 |
|
| 927 |
- ret = cli_checklimits("dmg_stripe_bzip", ctx, (unsigned long)(size_so_far + sizeof(obuf)), 0, 0);
|
|
| 927 |
+ ret = cli_checklimits("dmg_stripe_bzip", ctx, size_so_far + sizeof(obuf), 0, 0);
|
|
| 928 | 928 |
if (ret != CL_CLEAN) {
|
| 929 | 929 |
break; |
| 930 | 930 |
} |
| ... | ... |
@@ -953,7 +953,7 @@ static int dmg_stripe_bzip(cli_ctx *ctx, int fd, uint32_t index, struct dmg_mish |
| 953 | 953 |
size_so_far += next_write; |
| 954 | 954 |
dmg_bzipmsg("dmg_stripe_bzip: size_so_far: " STDu64 " next_write: %zu\n", size_so_far, next_write);
|
| 955 | 955 |
|
| 956 |
- ret = cli_checklimits("dmg_stripe_bzip", ctx, (unsigned long)(size_so_far + sizeof(obuf)), 0, 0);
|
|
| 956 |
+ ret = cli_checklimits("dmg_stripe_bzip", ctx, size_so_far + sizeof(obuf), 0, 0);
|
|
| 957 | 957 |
if (ret != CL_CLEAN) {
|
| 958 | 958 |
break; |
| 959 | 959 |
} |
| ... | ... |
@@ -344,7 +344,7 @@ static cl_error_t hfsplus_scanfile(cli_ctx *ctx, hfsPlusVolumeHeader *volHeader, |
| 344 | 344 |
goto done; |
| 345 | 345 |
} |
| 346 | 346 |
#endif |
| 347 |
- status = cli_checklimits("hfsplus_scanfile", ctx, (unsigned long)targetSize, 0, 0);
|
|
| 347 |
+ status = cli_checklimits("hfsplus_scanfile", ctx, targetSize, 0, 0);
|
|
| 348 | 348 |
if (status != CL_SUCCESS) {
|
| 349 | 349 |
goto done; |
| 350 | 350 |
} |
| ... | ... |
@@ -116,12 +116,12 @@ int hm_addhash_bin(struct cli_matcher *root, const void *binhash, cli_hash_type_ |
| 116 | 116 |
if (!szh->hash_array) {
|
| 117 | 117 |
cli_errmsg("hm_addhash_bin: failed to grow hash array to %u entries\n", szh->items);
|
| 118 | 118 |
szh->items = 0; |
| 119 |
- MPOOL_FREE(root->mempool, szh->virusnames); |
|
| 119 |
+ MPOOL_FREE(root->mempool, (void *)szh->virusnames); |
|
| 120 | 120 |
szh->virusnames = NULL; |
| 121 | 121 |
return CL_EMEM; |
| 122 | 122 |
} |
| 123 | 123 |
|
| 124 |
- szh->virusnames = MPOOL_REALLOC2(root->mempool, szh->virusnames, sizeof(*szh->virusnames) * szh->items); |
|
| 124 |
+ szh->virusnames = MPOOL_REALLOC2(root->mempool, (void *)szh->virusnames, sizeof(*szh->virusnames) * szh->items); |
|
| 125 | 125 |
if (!szh->virusnames) {
|
| 126 | 126 |
cli_errmsg("hm_addhash_bin: failed to grow virusname array to %u entries\n", szh->items);
|
| 127 | 127 |
szh->items = 0; |
| ... | ... |
@@ -319,7 +319,7 @@ void hm_free(struct cli_matcher *root) |
| 319 | 319 |
MPOOL_FREE(root->mempool, szh->hash_array); |
| 320 | 320 |
while (szh->items) |
| 321 | 321 |
MPOOL_FREE(root->mempool, (void *)szh->virusnames[--szh->items]); |
| 322 |
- MPOOL_FREE(root->mempool, szh->virusnames); |
|
| 322 |
+ MPOOL_FREE(root->mempool, (void *)szh->virusnames); |
|
| 323 | 323 |
MPOOL_FREE(root->mempool, szh); |
| 324 | 324 |
} |
| 325 | 325 |
CLI_HTU32_FREE(ht, root->mempool); |
| ... | ... |
@@ -334,6 +334,6 @@ void hm_free(struct cli_matcher *root) |
| 334 | 334 |
MPOOL_FREE(root->mempool, szh->hash_array); |
| 335 | 335 |
while (szh->items) |
| 336 | 336 |
MPOOL_FREE(root->mempool, (void *)szh->virusnames[--szh->items]); |
| 337 |
- MPOOL_FREE(root->mempool, szh->virusnames); |
|
| 337 |
+ MPOOL_FREE(root->mempool, (void *)szh->virusnames); |
|
| 338 | 338 |
} |
| 339 | 339 |
} |
| ... | ... |
@@ -1726,7 +1726,7 @@ static cl_error_t handler_otf_encrypted(ole2_header_t *hdr, property_t *prop, co |
| 1726 | 1726 |
int nrounds = 0; |
| 1727 | 1727 |
uint8_t *decryptDst = NULL; |
| 1728 | 1728 |
encryption_key_t *key = (encryption_key_t *)handler_ctx; |
| 1729 |
- uint64_t *rk = NULL; |
|
| 1729 |
+ uint32_t *rk = NULL; |
|
| 1730 | 1730 |
uint32_t bytesRead = 0; |
| 1731 | 1731 |
uint64_t actualFileLength; |
| 1732 | 1732 |
uint64_t bytesWritten = 0; |
| ... | ... |
@@ -1746,7 +1746,7 @@ static cl_error_t handler_otf_encrypted(ole2_header_t *hdr, property_t *prop, co |
| 1746 | 1746 |
goto done; |
| 1747 | 1747 |
} |
| 1748 | 1748 |
|
| 1749 |
- CLI_MAX_MALLOC_OR_GOTO_DONE(rk, RKLENGTH(key->key_length_bits) * sizeof(uint64_t), ret = CL_EMEM); |
|
| 1749 |
+ CLI_MAX_MALLOC_OR_GOTO_DONE(rk, RKLENGTH(key->key_length_bits) * sizeof(uint32_t), ret = CL_EMEM); |
|
| 1750 | 1750 |
|
| 1751 | 1751 |
print_ole2_property(prop); |
| 1752 | 1752 |
|
| ... | ... |
@@ -2143,7 +2143,7 @@ done: |
| 2143 | 2143 |
|
| 2144 | 2144 |
static bool aes_128ecb_decrypt(const unsigned char *in, size_t length, unsigned char *out, const encryption_key_t *const key) |
| 2145 | 2145 |
{
|
| 2146 |
- uint64_t rk[RKLENGTH(128)]; |
|
| 2146 |
+ uint32_t rk[RKLENGTH(128)]; |
|
| 2147 | 2147 |
int nrounds; |
| 2148 | 2148 |
size_t i; |
| 2149 | 2149 |
bool bRet = false; |
| ... | ... |
@@ -250,7 +250,7 @@ static void *get_module_function(HMODULE handle, const char *name) |
| 250 | 250 |
NULL, |
| 251 | 251 |
lasterr, |
| 252 | 252 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 253 |
- (LPCSTR)&err, |
|
| 253 |
+ (LPSTR)&err, |
|
| 254 | 254 |
0, |
| 255 | 255 |
NULL); |
| 256 | 256 |
} |
| ... | ... |
@@ -1132,10 +1132,10 @@ void cli_append_potentially_unwanted_if_heur_exceedsmax(cli_ctx *ctx, char *vnam |
| 1132 | 1132 |
} |
| 1133 | 1133 |
} |
| 1134 | 1134 |
|
| 1135 |
-cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, unsigned long need2, unsigned long need3) |
|
| 1135 |
+cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, uint64_t need1, uint64_t need2, uint64_t need3) |
|
| 1136 | 1136 |
{
|
| 1137 | 1137 |
cl_error_t ret = CL_SUCCESS; |
| 1138 |
- unsigned long needed; |
|
| 1138 |
+ uint64_t needed; |
|
| 1139 | 1139 |
|
| 1140 | 1140 |
if (!ctx) {
|
| 1141 | 1141 |
/* if called without limits, go on, unpack, scan */ |
| ... | ... |
@@ -1156,7 +1156,7 @@ cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, u |
| 1156 | 1156 |
/* Enforce global scan-size limit, if limit enabled */ |
| 1157 | 1157 |
if (needed && (ctx->engine->maxscansize != 0) && (ctx->engine->maxscansize - ctx->scansize < needed)) {
|
| 1158 | 1158 |
/* The size needed is greater than the remaining scansize ... Skip this file. */ |
| 1159 |
- cli_dbgmsg("%s: scansize exceeded (initial: %lu, consumed: %lu, needed: %lu)\n", who, (unsigned long int)ctx->engine->maxscansize, (unsigned long int)ctx->scansize, needed);
|
|
| 1159 |
+ cli_dbgmsg("%s: scansize exceeded (initial: %lu, consumed: %lu, needed: %lu)\n", who, ctx->engine->maxscansize, ctx->scansize, needed);
|
|
| 1160 | 1160 |
ret = CL_EMAXSIZE; |
| 1161 | 1161 |
cli_append_potentially_unwanted_if_heur_exceedsmax(ctx, "Heuristics.Limits.Exceeded.MaxScanSize"); |
| 1162 | 1162 |
goto done; |
| ... | ... |
@@ -1165,7 +1165,7 @@ cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, u |
| 1165 | 1165 |
/* Enforce per-file file-size limit, if limit enabled */ |
| 1166 | 1166 |
if (needed && (ctx->engine->maxfilesize != 0) && (ctx->engine->maxfilesize < needed)) {
|
| 1167 | 1167 |
/* The size needed is greater than that limit ... Skip this file. */ |
| 1168 |
- cli_dbgmsg("%s: filesize exceeded (allowed: %lu, needed: %lu)\n", who, (unsigned long int)ctx->engine->maxfilesize, needed);
|
|
| 1168 |
+ cli_dbgmsg("%s: filesize exceeded (allowed: %lu, needed: %lu)\n", who, ctx->engine->maxfilesize, needed);
|
|
| 1169 | 1169 |
ret = CL_EMAXSIZE; |
| 1170 | 1170 |
cli_append_potentially_unwanted_if_heur_exceedsmax(ctx, "Heuristics.Limits.Exceeded.MaxFileSize"); |
| 1171 | 1171 |
goto done; |
| ... | ... |
@@ -593,16 +593,16 @@ extern LIBCLAMAV_EXPORT int have_rar; |
| 593 | 593 |
|
| 594 | 594 |
/* based on macros from A. Melnikoff */ |
| 595 | 595 |
#define cbswap16(v) (((v & 0xff) << 8) | (((v) >> 8) & 0xff)) |
| 596 |
-#define cbswap32(v) ((((v)&0x000000ff) << 24) | (((v)&0x0000ff00) << 8) | \ |
|
| 597 |
- (((v)&0x00ff0000) >> 8) | (((v)&0xff000000) >> 24)) |
|
| 598 |
-#define cbswap64(v) ((((v)&0x00000000000000ffULL) << 56) | \ |
|
| 599 |
- (((v)&0x000000000000ff00ULL) << 40) | \ |
|
| 600 |
- (((v)&0x0000000000ff0000ULL) << 24) | \ |
|
| 601 |
- (((v)&0x00000000ff000000ULL) << 8) | \ |
|
| 602 |
- (((v)&0x000000ff00000000ULL) >> 8) | \ |
|
| 603 |
- (((v)&0x0000ff0000000000ULL) >> 24) | \ |
|
| 604 |
- (((v)&0x00ff000000000000ULL) >> 40) | \ |
|
| 605 |
- (((v)&0xff00000000000000ULL) >> 56)) |
|
| 596 |
+#define cbswap32(v) ((((v) & 0x000000ff) << 24) | (((v) & 0x0000ff00) << 8) | \ |
|
| 597 |
+ (((v) & 0x00ff0000) >> 8) | (((v) & 0xff000000) >> 24)) |
|
| 598 |
+#define cbswap64(v) ((((v) & 0x00000000000000ffULL) << 56) | \ |
|
| 599 |
+ (((v) & 0x000000000000ff00ULL) << 40) | \ |
|
| 600 |
+ (((v) & 0x0000000000ff0000ULL) << 24) | \ |
|
| 601 |
+ (((v) & 0x00000000ff000000ULL) << 8) | \ |
|
| 602 |
+ (((v) & 0x000000ff00000000ULL) >> 8) | \ |
|
| 603 |
+ (((v) & 0x0000ff0000000000ULL) >> 24) | \ |
|
| 604 |
+ (((v) & 0x00ff000000000000ULL) >> 40) | \ |
|
| 605 |
+ (((v) & 0xff00000000000000ULL) >> 56)) |
|
| 606 | 606 |
|
| 607 | 607 |
#ifndef HAVE_ATTRIB_PACKED |
| 608 | 608 |
#define __attribute__(x) |
| ... | ... |
@@ -828,8 +828,8 @@ size_t cli_recursion_stack_get_size(cli_ctx *ctx, int index); |
| 828 | 828 |
/* used by: spin, yc (C) aCaB */ |
| 829 | 829 |
#define __SHIFTBITS(a) (sizeof(a) << 3) |
| 830 | 830 |
#define __SHIFTMASK(a) (__SHIFTBITS(a) - 1) |
| 831 |
-#define CLI_ROL(a, b) a = (a << ((b)&__SHIFTMASK(a))) | (a >> ((__SHIFTBITS(a) - (b)) & __SHIFTMASK(a))) |
|
| 832 |
-#define CLI_ROR(a, b) a = (a >> ((b)&__SHIFTMASK(a))) | (a << ((__SHIFTBITS(a) - (b)) & __SHIFTMASK(a))) |
|
| 831 |
+#define CLI_ROL(a, b) a = (a << ((b) & __SHIFTMASK(a))) | (a >> ((__SHIFTBITS(a) - (b)) & __SHIFTMASK(a))) |
|
| 832 |
+#define CLI_ROR(a, b) a = (a >> ((b) & __SHIFTMASK(a))) | (a << ((__SHIFTBITS(a) - (b)) & __SHIFTMASK(a))) |
|
| 833 | 833 |
|
| 834 | 834 |
/* Implementation independent sign-extended signed right shift */ |
| 835 | 835 |
#ifdef HAVE_SAR |
| ... | ... |
@@ -1143,7 +1143,7 @@ int cli_bitset_set(bitset_t *bs, unsigned long bit_offset); |
| 1143 | 1143 |
int cli_bitset_test(bitset_t *bs, unsigned long bit_offset); |
| 1144 | 1144 |
const char *cli_ctime(const time_t *timep, char *buf, const size_t bufsize); |
| 1145 | 1145 |
|
| 1146 |
-cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, unsigned long need2, unsigned long need3); |
|
| 1146 |
+cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, uint64_t need1, uint64_t need2, uint64_t need3); |
|
| 1147 | 1147 |
|
| 1148 | 1148 |
/** |
| 1149 | 1149 |
* @brief Call before scanning a file to determine if we should scan it, skip it, or abort the entire scanning process. |
| ... | ... |
@@ -1157,7 +1157,6 @@ cl_error_t cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, u |
| 1157 | 1157 |
*/ |
| 1158 | 1158 |
cl_error_t cli_updatelimits(cli_ctx *ctx, size_t needed); |
| 1159 | 1159 |
|
| 1160 |
-unsigned long cli_getsizelimit(cli_ctx *, unsigned long); |
|
| 1161 | 1160 |
int cli_matchregex(const char *str, const char *regex); |
| 1162 | 1161 |
void cli_qsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *)); |
| 1163 | 1162 |
void cli_qsort_r(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *, const void *), void *arg); |
| ... | ... |
@@ -1333,7 +1332,7 @@ uint8_t cli_set_debug_flag(uint8_t debug_flag); |
| 1333 | 1333 |
#define CLI_FREE_AND_SET_NULL(var) \ |
| 1334 | 1334 |
do { \
|
| 1335 | 1335 |
if (NULL != var) { \
|
| 1336 |
- free(var); \ |
|
| 1336 |
+ free((void *)var); \ |
|
| 1337 | 1337 |
var = NULL; \ |
| 1338 | 1338 |
} \ |
| 1339 | 1339 |
} while (0) |
| ... | ... |
@@ -1461,16 +1460,16 @@ uint8_t cli_set_debug_flag(uint8_t debug_flag); |
| 1461 | 1461 |
* @param ... The error handling code to execute if the allocation fails. |
| 1462 | 1462 |
*/ |
| 1463 | 1463 |
#ifndef CLI_MAX_REALLOC_OR_GOTO_DONE |
| 1464 |
-#define CLI_MAX_REALLOC_OR_GOTO_DONE(ptr, size, ...) \ |
|
| 1465 |
- do { \
|
|
| 1466 |
- void *vTmp = cli_max_realloc(ptr, size); \ |
|
| 1467 |
- if (NULL == vTmp) { \
|
|
| 1468 |
- do { \
|
|
| 1469 |
- __VA_ARGS__; \ |
|
| 1470 |
- } while (0); \ |
|
| 1471 |
- goto done; \ |
|
| 1472 |
- } \ |
|
| 1473 |
- ptr = vTmp; \ |
|
| 1464 |
+#define CLI_MAX_REALLOC_OR_GOTO_DONE(ptr, size, ...) \ |
|
| 1465 |
+ do { \
|
|
| 1466 |
+ void *vTmp = cli_max_realloc((void *)ptr, size); \ |
|
| 1467 |
+ if (NULL == vTmp) { \
|
|
| 1468 |
+ do { \
|
|
| 1469 |
+ __VA_ARGS__; \ |
|
| 1470 |
+ } while (0); \ |
|
| 1471 |
+ goto done; \ |
|
| 1472 |
+ } \ |
|
| 1473 |
+ ptr = vTmp; \ |
|
| 1474 | 1474 |
} while (0) |
| 1475 | 1475 |
#endif |
| 1476 | 1476 |
|
| ... | ... |
@@ -1486,16 +1485,16 @@ uint8_t cli_set_debug_flag(uint8_t debug_flag); |
| 1486 | 1486 |
* @param ... The error handling code to execute if the allocation fails. |
| 1487 | 1487 |
*/ |
| 1488 | 1488 |
#ifndef CLI_SAFER_REALLOC_OR_GOTO_DONE |
| 1489 |
-#define CLI_SAFER_REALLOC_OR_GOTO_DONE(ptr, size, ...) \ |
|
| 1490 |
- do { \
|
|
| 1491 |
- void *vTmp = cli_safer_realloc(ptr, size); \ |
|
| 1492 |
- if (NULL == vTmp) { \
|
|
| 1493 |
- do { \
|
|
| 1494 |
- __VA_ARGS__; \ |
|
| 1495 |
- } while (0); \ |
|
| 1496 |
- goto done; \ |
|
| 1497 |
- } \ |
|
| 1498 |
- ptr = vTmp; \ |
|
| 1489 |
+#define CLI_SAFER_REALLOC_OR_GOTO_DONE(ptr, size, ...) \ |
|
| 1490 |
+ do { \
|
|
| 1491 |
+ void *vTmp = cli_safer_realloc((void *)ptr, size); \ |
|
| 1492 |
+ if (NULL == vTmp) { \
|
|
| 1493 |
+ do { \
|
|
| 1494 |
+ __VA_ARGS__; \ |
|
| 1495 |
+ } while (0); \ |
|
| 1496 |
+ goto done; \ |
|
| 1497 |
+ } \ |
|
| 1498 |
+ ptr = vTmp; \ |
|
| 1499 | 1499 |
} while (0) |
| 1500 | 1500 |
#endif |
| 1501 | 1501 |
|
| ... | ... |
@@ -980,7 +980,7 @@ static cl_error_t cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ |
| 980 | 980 |
* used */ |
| 981 | 981 |
const char *cli_strerror(int errnum, char *buf, size_t len) |
| 982 | 982 |
{
|
| 983 |
- char *err; |
|
| 983 |
+ const char *err; |
|
| 984 | 984 |
#ifdef CL_THREAD_SAFE |
| 985 | 985 |
pthread_mutex_lock(&cli_strerror_mutex); |
| 986 | 986 |
#endif |
| ... | ... |
@@ -742,8 +742,8 @@ static size_t filter_writen(struct pdf_struct *pdf, struct pdf_obj *obj, int fou |
| 742 | 742 |
{
|
| 743 | 743 |
UNUSEDPARAM(obj); |
| 744 | 744 |
|
| 745 |
- if (cli_checklimits("pdf", pdf->ctx, (unsigned long)*sum, 0, 0)) /* TODO: May truncate for large values on 64-bit platforms */
|
|
| 746 |
- return len; /* pretend it was a successful write to suppress CL_EWRITE */ |
|
| 745 |
+ if (cli_checklimits("pdf", pdf->ctx, (uint64_t)*sum, 0, 0))
|
|
| 746 |
+ return len; |
|
| 747 | 747 |
|
| 748 | 748 |
*sum += len; |
| 749 | 749 |
|
| ... | ... |
@@ -1083,7 +1083,7 @@ static void dbg_printhex(const char *msg, const char *hex, unsigned len); |
| 1083 | 1083 |
|
| 1084 | 1084 |
static void aes_256cbc_decrypt(const unsigned char *in, size_t *length, unsigned char *q, char *key, unsigned key_n, int has_iv) |
| 1085 | 1085 |
{
|
| 1086 |
- unsigned long rk[RKLENGTH(256)]; |
|
| 1086 |
+ uint32_t rk[RKLENGTH(256)]; |
|
| 1087 | 1087 |
unsigned char iv[16]; |
| 1088 | 1088 |
size_t len = 0; |
| 1089 | 1089 |
unsigned char pad, i; |
| ... | ... |
@@ -1171,7 +1171,7 @@ static void aes_256cbc_decrypt(const unsigned char *in, size_t *length, unsigned |
| 1171 | 1171 |
|
| 1172 | 1172 |
static void aes_128cbc_encrypt(const unsigned char *in, size_t in_length, unsigned char *out, size_t *out_length, const unsigned char *key, size_t key_n, const unsigned char *iv) |
| 1173 | 1173 |
{
|
| 1174 |
- unsigned long rk[RKLENGTH(128)]; |
|
| 1174 |
+ uint32_t rk[RKLENGTH(128)]; |
|
| 1175 | 1175 |
unsigned char real_iv[16] = {0};
|
| 1176 | 1176 |
int nrounds; |
| 1177 | 1177 |
uint8_t i = 0; |
| ... | ... |
@@ -3,10 +3,7 @@ |
| 3 | 3 |
|
| 4 | 4 |
#include "rijndael.h" |
| 5 | 5 |
|
| 6 |
-typedef unsigned long u32; |
|
| 7 |
-typedef unsigned char u8; |
|
| 8 |
- |
|
| 9 |
-static const u32 Te0[256] = |
|
| 6 |
+static const uint32_t Te0[256] = |
|
| 10 | 7 |
{
|
| 11 | 8 |
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, |
| 12 | 9 |
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, |
| ... | ... |
@@ -74,7 +71,7 @@ static const u32 Te0[256] = |
| 74 | 74 |
0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, |
| 75 | 75 |
}; |
| 76 | 76 |
|
| 77 |
-static const u32 Te1[256] = |
|
| 77 |
+static const uint32_t Te1[256] = |
|
| 78 | 78 |
{
|
| 79 | 79 |
0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, |
| 80 | 80 |
0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, |
| ... | ... |
@@ -142,7 +139,7 @@ static const u32 Te1[256] = |
| 142 | 142 |
0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, |
| 143 | 143 |
}; |
| 144 | 144 |
|
| 145 |
-static const u32 Te2[256] = |
|
| 145 |
+static const uint32_t Te2[256] = |
|
| 146 | 146 |
{
|
| 147 | 147 |
0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, |
| 148 | 148 |
0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, |
| ... | ... |
@@ -210,7 +207,7 @@ static const u32 Te2[256] = |
| 210 | 210 |
0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, |
| 211 | 211 |
}; |
| 212 | 212 |
|
| 213 |
-static const u32 Te3[256] = |
|
| 213 |
+static const uint32_t Te3[256] = |
|
| 214 | 214 |
{
|
| 215 | 215 |
0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, |
| 216 | 216 |
0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, |
| ... | ... |
@@ -278,7 +275,7 @@ static const u32 Te3[256] = |
| 278 | 278 |
0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, |
| 279 | 279 |
}; |
| 280 | 280 |
|
| 281 |
-static const u32 Te4[256] = |
|
| 281 |
+static const uint32_t Te4[256] = |
|
| 282 | 282 |
{
|
| 283 | 283 |
0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, |
| 284 | 284 |
0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, |
| ... | ... |
@@ -346,7 +343,7 @@ static const u32 Te4[256] = |
| 346 | 346 |
0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, |
| 347 | 347 |
}; |
| 348 | 348 |
|
| 349 |
-static const u32 Td0[256] = |
|
| 349 |
+static const uint32_t Td0[256] = |
|
| 350 | 350 |
{
|
| 351 | 351 |
0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, |
| 352 | 352 |
0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, |
| ... | ... |
@@ -414,7 +411,7 @@ static const u32 Td0[256] = |
| 414 | 414 |
0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, |
| 415 | 415 |
}; |
| 416 | 416 |
|
| 417 |
-static const u32 Td1[256] = |
|
| 417 |
+static const uint32_t Td1[256] = |
|
| 418 | 418 |
{
|
| 419 | 419 |
0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, |
| 420 | 420 |
0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, |
| ... | ... |
@@ -482,7 +479,7 @@ static const u32 Td1[256] = |
| 482 | 482 |
0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, |
| 483 | 483 |
}; |
| 484 | 484 |
|
| 485 |
-static const u32 Td2[256] = |
|
| 485 |
+static const uint32_t Td2[256] = |
|
| 486 | 486 |
{
|
| 487 | 487 |
0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, |
| 488 | 488 |
0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, |
| ... | ... |
@@ -550,7 +547,7 @@ static const u32 Td2[256] = |
| 550 | 550 |
0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, |
| 551 | 551 |
}; |
| 552 | 552 |
|
| 553 |
-static const u32 Td3[256] = |
|
| 553 |
+static const uint32_t Td3[256] = |
|
| 554 | 554 |
{
|
| 555 | 555 |
0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, |
| 556 | 556 |
0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, |
| ... | ... |
@@ -618,7 +615,7 @@ static const u32 Td3[256] = |
| 618 | 618 |
0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, |
| 619 | 619 |
}; |
| 620 | 620 |
|
| 621 |
-static const u32 Td4[256] = |
|
| 621 |
+static const uint32_t Td4[256] = |
|
| 622 | 622 |
{
|
| 623 | 623 |
0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, |
| 624 | 624 |
0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, |
| ... | ... |
@@ -686,7 +683,7 @@ static const u32 Td4[256] = |
| 686 | 686 |
0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, |
| 687 | 687 |
}; |
| 688 | 688 |
|
| 689 |
-static const u32 rcon[] = |
|
| 689 |
+static const uint32_t rcon[] = |
|
| 690 | 690 |
{
|
| 691 | 691 |
0x01000000, 0x02000000, 0x04000000, 0x08000000, |
| 692 | 692 |
0x10000000, 0x20000000, 0x40000000, 0x80000000, |
| ... | ... |
@@ -694,28 +691,28 @@ static const u32 rcon[] = |
| 694 | 694 |
/* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ |
| 695 | 695 |
}; |
| 696 | 696 |
|
| 697 |
-#define GETU32(plaintext) (((u32)(plaintext)[0] << 24) ^ \ |
|
| 698 |
- ((u32)(plaintext)[1] << 16) ^ \ |
|
| 699 |
- ((u32)(plaintext)[2] << 8) ^ \ |
|
| 700 |
- ((u32)(plaintext)[3])) |
|
| 697 |
+#define GETU32(plaintext) (((uint32_t)(plaintext)[0] << 24) ^ \ |
|
| 698 |
+ ((uint32_t)(plaintext)[1] << 16) ^ \ |
|
| 699 |
+ ((uint32_t)(plaintext)[2] << 8) ^ \ |
|
| 700 |
+ ((uint32_t)(plaintext)[3])) |
|
| 701 | 701 |
|
| 702 |
-#define PUTU32(ciphertext, st) { (ciphertext)[0] = (u8)((st) >> 24); \
|
|
| 703 |
- (ciphertext)[1] = (u8)((st) >> 16); \ |
|
| 704 |
- (ciphertext)[2] = (u8)((st) >> 8); \ |
|
| 705 |
- (ciphertext)[3] = (u8)(st); } |
|
| 702 |
+#define PUTU32(ciphertext, st) { (ciphertext)[0] = (uint8_t)((st) >> 24); \
|
|
| 703 |
+ (ciphertext)[1] = (uint8_t)((st) >> 16); \ |
|
| 704 |
+ (ciphertext)[2] = (uint8_t)((st) >> 8); \ |
|
| 705 |
+ (ciphertext)[3] = (uint8_t)(st); } |
|
| 706 | 706 |
|
| 707 |
-int rijndaelSetupEncrypt(u32 *rk, const u8 *key, int keybits); |
|
| 708 |
-void rijndaelEncrypt(const u32 *rk, int nrounds, const u8 plaintext[16], u8 ciphertext[16]); |
|
| 707 |
+int rijndaelSetupEncrypt(uint32_t *rk, const uint8_t *key, int keybits); |
|
| 708 |
+void rijndaelEncrypt(const uint32_t *rk, int nrounds, const uint8_t plaintext[16], uint8_t ciphertext[16]); |
|
| 709 | 709 |
|
| 710 | 710 |
/** |
| 711 | 711 |
* Expand the cipher key into the encryption key schedule. |
| 712 | 712 |
* |
| 713 | 713 |
* @return the number of rounds for the given cipher key size. |
| 714 | 714 |
*/ |
| 715 |
-int rijndaelSetupEncrypt(u32 *rk, const u8 *key, int keybits) |
|
| 715 |
+int rijndaelSetupEncrypt(uint32_t *rk, const uint8_t *key, int keybits) |
|
| 716 | 716 |
{
|
| 717 | 717 |
int i = 0; |
| 718 |
- u32 temp; |
|
| 718 |
+ uint32_t temp; |
|
| 719 | 719 |
|
| 720 | 720 |
rk[0] = GETU32(key ); |
| 721 | 721 |
rk[1] = GETU32(key + 4); |
| ... | ... |
@@ -801,10 +798,10 @@ int rijndaelSetupEncrypt(u32 *rk, const u8 *key, int keybits) |
| 801 | 801 |
* |
| 802 | 802 |
* @return the number of rounds for the given cipher key size. |
| 803 | 803 |
*/ |
| 804 |
-int rijndaelSetupDecrypt(u32 *rk, const u8 *key, int keybits) |
|
| 804 |
+int rijndaelSetupDecrypt(uint32_t *rk, const uint8_t *key, int keybits) |
|
| 805 | 805 |
{
|
| 806 | 806 |
int nrounds, i, j; |
| 807 |
- u32 temp; |
|
| 807 |
+ uint32_t temp; |
|
| 808 | 808 |
|
| 809 | 809 |
/* expand the cipher key: */ |
| 810 | 810 |
nrounds = rijndaelSetupEncrypt(rk, key, keybits); |
| ... | ... |
@@ -844,10 +841,10 @@ int rijndaelSetupDecrypt(u32 *rk, const u8 *key, int keybits) |
| 844 | 844 |
return nrounds; |
| 845 | 845 |
} |
| 846 | 846 |
|
| 847 |
-void rijndaelEncrypt(const u32 *rk, int nrounds, const u8 plaintext[16], |
|
| 848 |
- u8 ciphertext[16]) |
|
| 847 |
+void rijndaelEncrypt(const uint32_t *rk, int nrounds, const uint8_t plaintext[16], |
|
| 848 |
+ uint8_t ciphertext[16]) |
|
| 849 | 849 |
{
|
| 850 |
- u32 s0, s1, s2, s3, t0, t1, t2, t3; |
|
| 850 |
+ uint32_t s0, s1, s2, s3, t0, t1, t2, t3; |
|
| 851 | 851 |
#ifndef FULL_UNROLL |
| 852 | 852 |
int r; |
| 853 | 853 |
#endif /* ?FULL_UNROLL */ |
| ... | ... |
@@ -1026,10 +1023,10 @@ void rijndaelEncrypt(const u32 *rk, int nrounds, const u8 plaintext[16], |
| 1026 | 1026 |
PUTU32(ciphertext + 12, s3); |
| 1027 | 1027 |
} |
| 1028 | 1028 |
|
| 1029 |
-void rijndaelDecrypt(const u32 *rk, int nrounds, const u8 ciphertext[16], |
|
| 1030 |
- u8 plaintext[16]) |
|
| 1029 |
+void rijndaelDecrypt(const uint32_t *rk, int nrounds, const uint8_t ciphertext[16], |
|
| 1030 |
+ uint8_t plaintext[16]) |
|
| 1031 | 1031 |
{
|
| 1032 |
- u32 s0, s1, s2, s3, t0, t1, t2, t3; |
|
| 1032 |
+ uint32_t s0, s1, s2, s3, t0, t1, t2, t3; |
|
| 1033 | 1033 |
#ifndef FULL_UNROLL |
| 1034 | 1034 |
int r; |
| 1035 | 1035 |
#endif /* ?FULL_UNROLL */ |
| ... | ... |
@@ -1208,4 +1205,3 @@ void rijndaelDecrypt(const u32 *rk, int nrounds, const u8 ciphertext[16], |
| 1208 | 1208 |
rk[3]; |
| 1209 | 1209 |
PUTU32(plaintext + 12, s3); |
| 1210 | 1210 |
} |
| 1211 |
- |
| ... | ... |
@@ -1,15 +1,17 @@ |
| 1 |
+/* public domain code from http://www.efgh.com/software/rijndael.htm */ |
|
| 1 | 2 |
#ifndef H__RIJNDAEL |
| 2 | 3 |
#define H__RIJNDAEL |
| 3 | 4 |
|
| 4 |
-int rijndaelSetupDecrypt(unsigned long *rk, const unsigned char *key, int keybits); |
|
| 5 |
-void rijndaelDecrypt(const unsigned long *rk, int nrounds, const unsigned char ciphertext[16], unsigned char plaintext[16]); |
|
| 5 |
+#include "clamav-types.h" |
|
| 6 | 6 |
|
| 7 |
-int rijndaelSetupEncrypt(unsigned long *rk, const unsigned char *key, int keybits); |
|
| 8 |
-void rijndaelEncrypt(const unsigned long *rk, int nrounds, const unsigned char plaintext[16], unsigned char ciphertext[16]); |
|
| 7 |
+int rijndaelSetupDecrypt(uint32_t *rk, const unsigned char *key, int keybits); |
|
| 8 |
+void rijndaelDecrypt(const uint32_t *rk, int nrounds, const unsigned char ciphertext[16], unsigned char plaintext[16]); |
|
| 9 |
+ |
|
| 10 |
+int rijndaelSetupEncrypt(uint32_t *rk, const unsigned char *key, int keybits); |
|
| 11 |
+void rijndaelEncrypt(const uint32_t *rk, int nrounds, const unsigned char plaintext[16], unsigned char ciphertext[16]); |
|
| 9 | 12 |
|
| 10 | 13 |
#define KEYLENGTH(keybits) ((keybits)/8) |
| 11 | 14 |
#define RKLENGTH(keybits) ((keybits)/8+28) |
| 12 | 15 |
#define NROUNDS(keybits) ((keybits)/32+6) |
| 13 | 16 |
|
| 14 | 17 |
#endif |
| 15 |
- |
| ... | ... |
@@ -1556,8 +1556,6 @@ done: |
| 1556 | 1556 |
return ret; |
| 1557 | 1557 |
} |
| 1558 | 1558 |
|
| 1559 |
-#define min(x, y) ((x) < (y) ? (x) : (y)) |
|
| 1560 |
- |
|
| 1561 | 1559 |
/** |
| 1562 | 1560 |
* Find a file in a directory tree. |
| 1563 | 1561 |
* \param filename Name of the file to find |
| ... | ... |
@@ -1596,7 +1594,7 @@ cl_error_t find_file(const char *filename, const char *dir, char *result, size_t |
| 1596 | 1596 |
} |
| 1597 | 1597 |
} else if (S_ISREG(statbuf.st_mode)) {
|
| 1598 | 1598 |
if (strcmp(dent->d_name, filename) == 0) {
|
| 1599 |
- len = min(strlen(dir) + 1, result_size); |
|
| 1599 |
+ len = MIN(strlen(dir) + 1, result_size); |
|
| 1600 | 1600 |
memcpy(result, dir, len); |
| 1601 | 1601 |
result[len - 1] = '\0'; |
| 1602 | 1602 |
closedir(dd); |
| ... | ... |
@@ -166,14 +166,14 @@ enum {
|
| 166 | 166 |
else { \
|
| 167 | 167 |
if ((N) < sleft) { \
|
| 168 | 168 |
cli_dbgmsg("SIS: Refusing to seek back\n"); \
|
| 169 |
- free(alangs); \ |
|
| 169 |
+ free((void *)alangs); \ |
|
| 170 | 170 |
return CL_CLEAN; \ |
| 171 | 171 |
} \ |
| 172 | 172 |
pos += (N)-sleft; \ |
| 173 | 173 |
size_t tmp = fmap_readn(map, buff, pos, BUFSIZ); \ |
| 174 | 174 |
if (((size_t)-1) == tmp) { \
|
| 175 | 175 |
cli_dbgmsg("SIS: Read failed during SKIP\n"); \
|
| 176 |
- free(alangs); \ |
|
| 176 |
+ free((void *)alangs); \ |
|
| 177 | 177 |
return CL_CLEAN; \ |
| 178 | 178 |
} \ |
| 179 | 179 |
sleft = smax = tmp; \ |
| ... | ... |
@@ -628,7 +628,7 @@ enum { T_INVALID,
|
| 628 | 628 |
|
| 629 | 629 |
const char *sisfields[] = {"Invalid", "String", "Array", "Compressed", "Version", "VersionRange", "Date", "Time", "DateTime", "Uid", "Unused", "Language", "Contents", "Controller", "Info", "SupportedLanguages", "SupportedOptions", "Prerequisites", "Dependency", "Properties", "Property", "Signatures", "CertificateChain", "Logo", "FileDescription", "Hash", "If", "ElseIf", "InstallBlock", "Expression", "Data", "DataUnit", "FileData", "SupportedOption", "ControllerChecksum", "DataChecksum", "Signature", "Blob", "SignatureAlgorithm", "SignatureCertificateChain", "DataIndex", "Capabilities"};
|
| 630 | 630 |
|
| 631 |
-#define ALIGN4(x) (((x) & ~3) + ((((x)&1) | (((x) >> 1) & 1)) << 2)) |
|
| 631 |
+#define ALIGN4(x) (((x) & ~3) + ((((x) & 1) | (((x) >> 1) & 1)) << 2)) |
|
| 632 | 632 |
|
| 633 | 633 |
#define HERE printf("here\n"), abort();
|
| 634 | 634 |
|
| ... | ... |
@@ -331,7 +331,7 @@ cl_error_t cli_untar(const char *dir, unsigned int posix, cli_ctx *ctx) |
| 331 | 331 |
if (limitnear > 0) {
|
| 332 | 332 |
currsize += nbytes; |
| 333 | 333 |
cli_dbgmsg("cli_untar: Approaching limit...\n");
|
| 334 |
- if (cli_checklimits("cli_untar", ctx, (unsigned long)currsize, 0, 0) != CL_SUCCESS) {
|
|
| 334 |
+ if (cli_checklimits("cli_untar", ctx, (uint64_t)currsize, 0, 0) != CL_SUCCESS) {
|
|
| 335 | 335 |
// Limit would be exceeded by this file, suppress writing beyond limit |
| 336 | 336 |
// Need to keep reading to get to end of file chunk |
| 337 | 337 |
skipwrite++; |
| ... | ... |
@@ -811,9 +811,9 @@ extern "C" {
|
| 811 | 811 |
pub fn cli_checklimits( |
| 812 | 812 |
who: *const ::std::os::raw::c_char, |
| 813 | 813 |
ctx: *mut cli_ctx, |
| 814 |
- need1: ::std::os::raw::c_ulong, |
|
| 815 |
- need2: ::std::os::raw::c_ulong, |
|
| 816 |
- need3: ::std::os::raw::c_ulong, |
|
| 814 |
+ need1: u64, |
|
| 815 |
+ need2: u64, |
|
| 816 |
+ need3: u64, |
|
| 817 | 817 |
) -> cl_error_t; |
| 818 | 818 |
} |
| 819 | 819 |
extern "C" {
|
| ... | ... |
@@ -2027,12 +2027,15 @@ static void check_version_compatible() |
| 2027 | 2027 |
} |
| 2028 | 2028 |
#endif |
| 2029 | 2029 |
|
| 2030 |
-int main(void) |
|
| 2030 |
+int main(int argc, char **argv) |
|
| 2031 | 2031 |
{
|
| 2032 | 2032 |
int nf; |
| 2033 | 2033 |
Suite *s; |
| 2034 | 2034 |
SRunner *sr; |
| 2035 | 2035 |
|
| 2036 |
+ UNUSEDPARAM(argc); |
|
| 2037 |
+ UNUSEDPARAM(argv); |
|
| 2038 |
+ |
|
| 2036 | 2039 |
cl_initialize_crypto(); |
| 2037 | 2040 |
|
| 2038 | 2041 |
fpu_words = get_fpu_endian(); |
| ... | ... |
@@ -890,10 +890,13 @@ static Suite *test_clamd_suite(void) |
| 890 | 890 |
return s; |
| 891 | 891 |
} |
| 892 | 892 |
|
| 893 |
-int main(void) |
|
| 893 |
+int main(int argc, char **argv) |
|
| 894 | 894 |
{
|
| 895 | 895 |
int num_fds; |
| 896 | 896 |
|
| 897 |
+ UNUSEDPARAM(argc); |
|
| 898 |
+ UNUSEDPARAM(argv); |
|
| 899 |
+ |
|
| 897 | 900 |
#ifdef _WIN32 |
| 898 | 901 |
WSADATA wsaData; |
| 899 | 902 |
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) {
|
| ... | ... |
@@ -143,7 +143,7 @@ START_TEST(test_suffix) |
| 143 | 143 |
ck_assert_msg(!!pattern, "test pattern"); |
| 144 | 144 |
preg = malloc(sizeof(*regex.preg)); |
| 145 | 145 |
ck_assert_msg(!!preg, "malloc"); |
| 146 |
- rc = cli_regex2suffix(pattern, preg, cb_expect_multi, tests[_i]); |
|
| 146 |
+ rc = cli_regex2suffix(pattern, preg, cb_expect_multi, (void *)tests[_i]); |
|
| 147 | 147 |
ck_assert_msg(rc == CL_SUCCESS, "single character pattern"); |
| 148 | 148 |
cli_regfree(preg); |
| 149 | 149 |
free(preg); |
| ... | ... |
@@ -355,7 +355,7 @@ int w32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, s |
| 355 | 355 |
return ret; |
| 356 | 356 |
} |
| 357 | 357 |
|
| 358 |
-int w32_accept(SOCKET sockfd, const struct sockaddr *addr, socklen_t *addrlen) |
|
| 358 |
+int w32_accept(SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen) |
|
| 359 | 359 |
{
|
| 360 | 360 |
if ((sockfd = accept(sockfd, addr, addrlen)) == INVALID_SOCKET) {
|
| 361 | 361 |
wsock2errno(); |
| ... | ... |
@@ -53,7 +53,7 @@ void w32_freeaddrinfo(struct addrinfo *res); |
| 53 | 53 |
const char *w32_inet_ntop(int af, const void *src, char *dst, socklen_t size); |
| 54 | 54 |
int w32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); |
| 55 | 55 |
int poll_with_event(struct pollfd *fds, int nfds, int timeout, HANDLE event); |
| 56 |
-int w32_accept(SOCKET sockfd, const struct sockaddr *addr, socklen_t *addrlen); |
|
| 56 |
+int w32_accept(SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen); |
|
| 57 | 57 |
int w32_listen(int sockfd, int backlog); |
| 58 | 58 |
int w32_shutdown(int sockfd, int how); |
| 59 | 59 |
int w32_getpeername(int sd, struct sockaddr *name, int *namelen); |
| ... | ... |
@@ -30,10 +30,10 @@ |
| 30 | 30 |
|
| 31 | 31 |
char *cli_strdup_to_utf8(const char *s) |
| 32 | 32 |
{
|
| 33 |
- char *r = cli_to_utf8_maybe_alloc(s); |
|
| 33 |
+ const char *r = cli_to_utf8_maybe_alloc(s); |
|
| 34 | 34 |
if (!r) return NULL; |
| 35 | 35 |
if (r == s) return _strdup(r); |
| 36 |
- return r; |
|
| 36 |
+ return (char *)r; |
|
| 37 | 37 |
} |
| 38 | 38 |
|
| 39 | 39 |
#define MAYBE_FREE_W \ |
| ... | ... |
@@ -44,7 +44,7 @@ char *cli_strdup_to_utf8(const char *s) |
| 44 | 44 |
do { \
|
| 45 | 45 |
if (utf8 != tmpu) free(utf8); \ |
| 46 | 46 |
} while (0) |
| 47 |
-char *cli_to_utf8_maybe_alloc(const char *s) |
|
| 47 |
+const char *cli_to_utf8_maybe_alloc(const char *s) |
|
| 48 | 48 |
{
|
| 49 | 49 |
int len = strlen(s) + 1; |
| 50 | 50 |
wchar_t tmpw[1024], *wdup; |