[Forensics-changes] [yara] 146/368: Add explicit alignments to data types taht may be read from disk.
Hilko Bengen
bengen at moszumanska.debian.org
Sat Jul 1 10:30:21 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 18eb24c1c6191c73a838a069b77323b365797fa1
Author: Hilko Bengen <bengen at hilluzination.de>
Date: Sun Jan 10 01:34:20 2016 +0100
Add explicit alignments to data types taht may be read from disk.
This fixes Github issue #389
---
libyara/include/yara/types.h | 13 +++++++------
libyara/include/yara/utils.h | 8 ++++++++
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/libyara/include/yara/types.h b/libyara/include/yara/types.h
index 6925398..5897651 100644
--- a/libyara/include/yara/types.h
+++ b/libyara/include/yara/types.h
@@ -22,6 +22,7 @@ limitations under the License.
#include <yara/re.h>
#include <yara/limits.h>
#include <yara/hash.h>
+#include <yara/utils.h>
#ifdef _WIN32
#include <windows.h>
@@ -39,7 +40,7 @@ typedef int32_t tidx_mask_t;
#define DECLARE_REFERENCE(type, name) \
- union { type name; int64_t name##_; }
+ union { type name; int64_t name##_; } YR_ALIGN(8)
#pragma pack(push)
#pragma pack(8)
@@ -68,7 +69,7 @@ typedef struct _YR_NAMESPACE
typedef struct _YR_META
{
int32_t type;
- int64_t integer;
+ YR_ALIGN(8) int64_t integer;
DECLARE_REFERENCE(const char*, identifier);
DECLARE_REFERENCE(char*, string);
@@ -85,10 +86,10 @@ typedef struct _YR_MATCH
union {
uint8_t* data; // Confirmed matches use "data",
int32_t chain_length; // unconfirmed ones use "chain_length"
- };
+ } YR_ALIGN(8);
- struct _YR_MATCH* prev;
- struct _YR_MATCH* next;
+ YR_ALIGN(8) struct _YR_MATCH* prev;
+ YR_ALIGN(8) struct _YR_MATCH* next;
} YR_MATCH;
@@ -259,7 +260,7 @@ typedef struct _YR_EXTERNAL_VARIABLE
{
int32_t type;
- union {
+ YR_ALIGN(8) union {
int64_t i;
double f;
char* s;
diff --git a/libyara/include/yara/utils.h b/libyara/include/yara/utils.h
index a387aa5..0fcc1b4 100644
--- a/libyara/include/yara/utils.h
+++ b/libyara/include/yara/utils.h
@@ -44,6 +44,14 @@ limitations under the License.
#define YR_API EXTERNC
#endif
+#if defined(__GNUC__)
+#define YR_ALIGN(n) __attribute__((aligned(n)))
+#elif defined(_MSC_VER)
+#define YR_ALIGN(n) __declspec(align(n))
+#else
+#define YR_ALIGN(n)
+#endif
+
#define yr_min(x, y) ((x < y) ? (x) : (y))
#define yr_max(x, y) ((x > y) ? (x) : (y))
--
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