[Forensics-changes] [yara] 48/368: Fix multiple warnings
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:30:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag v3.5.0
in repository yara.
commit 9397c305e420b69b72962313668ad941539c7e16
Author: Victor M. Alvarez <vmalvarez at virustotal.com>
Date: Mon Sep 14 11:55:15 2015 +0200
Fix multiple warnings
---
libyara/arena.c | 6 ++++--
libyara/exec.c | 24 ++++++++++++------------
libyara/filemap.c | 4 ++--
libyara/include/yara/strutils.h | 6 +++---
libyara/modules.c | 3 ---
libyara/modules/hash.c | 18 ++++++++++--------
libyara/modules/pe.c | 4 ++--
libyara/object.c | 2 +-
libyara/parser.c | 2 +-
libyara/scan.c | 15 ++++++---------
libyara/strutils.c | 6 +++---
11 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/libyara/arena.c b/libyara/arena.c
index 5fda13a..b577597 100644
--- a/libyara/arena.c
+++ b/libyara/arena.c
@@ -42,7 +42,7 @@ from files.
typedef struct _ARENA_FILE_HEADER
{
char magic[4];
- uint64_t size;
+ uint32_t size;
uint8_t version;
} ARENA_FILE_HEADER;
@@ -1027,11 +1027,13 @@ int yr_arena_save_stream(
reloc = reloc->next;
}
+ assert(page->size < 0x100000000); // 4GB
+
header.magic[0] = 'Y';
header.magic[1] = 'A';
header.magic[2] = 'R';
header.magic[3] = 'A';
- header.size = page->size;
+ header.size = (int32_t) page->size;
header.version = ARENA_FILE_VERSION;
yr_stream_write(&header, sizeof(header), 1, stream);
diff --git a/libyara/exec.c b/libyara/exec.c
index 6cb25ca..dbb6d29 100644
--- a/libyara/exec.c
+++ b/libyara/exec.c
@@ -731,73 +731,73 @@ int yr_execute_code(
case OP_INT8:
pop(r1);
- r1.i = read_int8_t_little_endian(context->mem_block, r1.i);
+ r1.i = read_int8_t_little_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_INT16:
pop(r1);
- r1.i = read_int16_t_little_endian(context->mem_block, r1.i);
+ r1.i = read_int16_t_little_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_INT32:
pop(r1);
- r1.i = read_int32_t_little_endian(context->mem_block, r1.i);
+ r1.i = read_int32_t_little_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_UINT8:
pop(r1);
- r1.i = read_uint8_t_little_endian(context->mem_block, r1.i);
+ r1.i = read_uint8_t_little_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_UINT16:
pop(r1);
- r1.i = read_uint16_t_little_endian(context->mem_block, r1.i);
+ r1.i = read_uint16_t_little_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_UINT32:
pop(r1);
- r1.i = read_uint32_t_little_endian(context->mem_block, r1.i);
+ r1.i = read_uint32_t_little_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_INT8BE:
pop(r1);
- r1.i = read_int8_t_big_endian(context->mem_block, r1.i);
+ r1.i = read_int8_t_big_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_INT16BE:
pop(r1);
- r1.i = read_int16_t_big_endian(context->mem_block, r1.i);
+ r1.i = read_int16_t_big_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_INT32BE:
pop(r1);
- r1.i = read_int32_t_big_endian(context->mem_block, r1.i);
+ r1.i = read_int32_t_big_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_UINT8BE:
pop(r1);
- r1.i = read_uint8_t_big_endian(context->mem_block, r1.i);
+ r1.i = read_uint8_t_big_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_UINT16BE:
pop(r1);
- r1.i = read_uint16_t_big_endian(context->mem_block, r1.i);
+ r1.i = read_uint16_t_big_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
case OP_UINT32BE:
pop(r1);
- r1.i = read_uint32_t_big_endian(context->mem_block, r1.i);
+ r1.i = read_uint32_t_big_endian(context->mem_block, (size_t) r1.i);
push(r1);
break;
diff --git a/libyara/filemap.c b/libyara/filemap.c
index 6f63765..603a38e 100644
--- a/libyara/filemap.c
+++ b/libyara/filemap.c
@@ -187,9 +187,9 @@ YR_API int yr_filemap_map_fd(
return ERROR_COULD_NOT_MAP_FILE;
if (size == 0)
- size = st.st_size - offset;
+ size = (size_t) (st.st_size - offset);
- pmapped_file->size = yr_min(size, st.st_size - offset);
+ pmapped_file->size = yr_min(size, (size_t) (st.st_size - offset));
if (pmapped_file->size != 0)
{
diff --git a/libyara/include/yara/strutils.h b/libyara/include/yara/strutils.h
index f12125a..7198287 100644
--- a/libyara/include/yara/strutils.h
+++ b/libyara/include/yara/strutils.h
@@ -34,7 +34,7 @@ uint64_t xtoi(
const char* hexstr);
-#if !HAVE_STRLCPY
+#if !HAVE_STRLCPY && !defined(strlcpy)
size_t strlcpy(
char *dst,
const char *src,
@@ -42,7 +42,7 @@ size_t strlcpy(
#endif
-#if !HAVE_STRLCAT
+#if !HAVE_STRLCAT && !defined(strlcat)
size_t strlcat(
char *dst,
const char *src,
@@ -50,7 +50,7 @@ size_t strlcat(
#endif
-#if !HAVE_MEMMEM
+#if !HAVE_MEMMEM && !defined(memmem)
void* memmem(
const void *haystack,
size_t haystack_size,
diff --git a/libyara/modules.c b/libyara/modules.c
index feb107e..6b270f7 100644
--- a/libyara/modules.c
+++ b/libyara/modules.c
@@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-
-#include <config.h>
-
#include <yara/exec.h>
#include <yara/modules.h>
#include <yara/libyara.h>
diff --git a/libyara/modules/hash.c b/libyara/modules/hash.c
index 4191a0c..e3fc231 100644
--- a/libyara/modules/hash.c
+++ b/libyara/modules/hash.c
@@ -135,8 +135,9 @@ define_function(data_md5)
if (offset >= block->base &&
offset < block->base + block->size)
{
- uint64_t data_offset = offset - block->base;
- uint64_t data_len = yr_min(length, block->size - data_offset);
+ size_t data_offset = (size_t) (offset - block->base);
+ size_t data_len = (size_t) yr_min(
+ length, (size_t) (block->size - data_offset));
offset += data_len;
length -= data_len;
@@ -198,8 +199,9 @@ define_function(data_sha1)
if (offset >= block->base &&
offset < block->base + block->size)
{
- uint64_t data_offset = offset - block->base;
- uint64_t data_len = yr_min(length, block->size - data_offset);
+ size_t data_offset = (size_t) (offset - block->base);
+ size_t data_len = (size_t) yr_min(
+ length, (size_t) block->size - data_offset);
offset += data_len;
length -= data_len;
@@ -261,8 +263,8 @@ define_function(data_sha256)
if (offset >= block->base &&
offset < block->base + block->size)
{
- uint64_t data_offset = offset - block->base;
- uint64_t data_len = yr_min(length, block->size - data_offset);
+ size_t data_offset = (size_t) (offset - block->base);
+ size_t data_len = (size_t) yr_min(length, block->size - data_offset);
offset += data_len;
length -= data_len;
@@ -318,8 +320,8 @@ define_function(data_checksum32)
if (offset >= block->base &&
offset < block->base + block->size)
{
- uint64_t data_offset = offset - block->base;
- uint64_t data_len = yr_min(length, block->size - data_offset);
+ size_t data_offset = (size_t) (offset - block->base);
+ size_t data_len = (size_t) yr_min(length, block->size - data_offset);
offset += data_len;
length -= data_len;
diff --git a/libyara/modules/pe.c b/libyara/modules/pe.c
index 4dcc13c..660bb00 100644
--- a/libyara/modules/pe.c
+++ b/libyara/modules/pe.c
@@ -1020,7 +1020,7 @@ IMPORTED_DLL* pe_parse_imports(
{
char* dll_name = (char *) (pe->data + offset);
- if (!pe_valid_dll_name(dll_name, pe->data_size - offset))
+ if (!pe_valid_dll_name(dll_name, pe->data_size - (size_t) offset))
break;
IMPORTED_FUNCTION* functions = pe_parse_import_descriptor(
@@ -1462,7 +1462,7 @@ define_function(exports)
char* name = (char*)(pe->data + offset);
- if (strncmp(name, function_name, pe->data_size - offset) == 0)
+ if (strncmp(name, function_name, pe->data_size - (size_t) offset) == 0)
return_integer(1);
}
diff --git a/libyara/object.c b/libyara/object.c
index 6bef40a..2bd3b55 100644
--- a/libyara/object.c
+++ b/libyara/object.c
@@ -42,7 +42,7 @@ int yr_object_create(
YR_OBJECT** object)
{
YR_OBJECT* obj;
- size_t object_size;
+ size_t object_size = 0;
switch (type)
{
diff --git a/libyara/parser.c b/libyara/parser.c
index dc4ebe4..6375ad8 100644
--- a/libyara/parser.c
+++ b/libyara/parser.c
@@ -1015,7 +1015,7 @@ int _yr_parser_operator_to_opcode(
const char* op,
int expression_type)
{
- int opcode;
+ int opcode = 0;
switch(expression_type)
{
diff --git a/libyara/scan.c b/libyara/scan.c
index 63419cc..10c379b 100644
--- a/libyara/scan.c
+++ b/libyara/scan.c
@@ -360,9 +360,6 @@ void _yr_scan_update_match_chain_length(
YR_MATCH* match_to_update,
int chain_length)
{
- YR_MATCH* match;
- size_t ending_offset;
-
if (match_to_update->chain_length == chain_length)
return;
@@ -371,11 +368,11 @@ void _yr_scan_update_match_chain_length(
if (string->chained_to == NULL)
return;
- match = string->chained_to->unconfirmed_matches[tidx].head;
+ YR_MATCH* match = string->chained_to->unconfirmed_matches[tidx].head;
while (match != NULL)
{
- ending_offset = match->offset + match->length;
+ int64_t ending_offset = match->offset + match->length;
if (ending_offset + string->chain_gap_max >= match_to_update->offset &&
ending_offset + string->chain_gap_min <= match_to_update->offset)
@@ -465,8 +462,8 @@ int _yr_scan_verify_chained_string_match(
YR_STRING* matching_string,
YR_SCAN_CONTEXT* context,
uint8_t* match_data,
- size_t match_base,
- size_t match_offset,
+ uint64_t match_base,
+ uint64_t match_offset,
int32_t match_length)
{
YR_STRING* string;
@@ -474,8 +471,8 @@ int _yr_scan_verify_chained_string_match(
YR_MATCH* next_match;
YR_MATCH* new_match;
- size_t lower_offset;
- size_t ending_offset;
+ uint64_t lower_offset;
+ uint64_t ending_offset;
int32_t full_chain_length;
int tidx = context->tidx;
diff --git a/libyara/strutils.c b/libyara/strutils.c
index 0684c53..f881da5 100644
--- a/libyara/strutils.c
+++ b/libyara/strutils.c
@@ -74,7 +74,7 @@ the following implementations were taken from OpenBSD.
*/
-#if !HAVE_STRLCPY
+#if !HAVE_STRLCPY && !defined(strlcpy)
size_t strlcpy(
char* dst,
@@ -113,7 +113,7 @@ size_t strlcpy(
#endif
-#if !HAVE_STRLCAT
+#if !HAVE_STRLCAT && !defined(strlcat)
size_t strlcat(
char* dst,
@@ -211,7 +211,7 @@ size_t strlcpy_w(
}
-#if !HAVE_MEMMEM
+#if !HAVE_MEMMEM && !defined(memmem)
void* memmem(
const void *haystack,
size_t haystack_size,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git
More information about the forensics-changes
mailing list