From 46b43fd75382d0aad3edfd13048cfef2906f6459 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 18 Dec 2024 10:22:42 +0100 Subject: [PATCH] scan-build: work around optin.performance.Padding Since the layout has to be preserved, padding is added. --- htp/htp.h | 12 ++++++++++++ htp/htp_core.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/htp/htp.h b/htp/htp.h index 36209ada..f01325e3 100644 --- a/htp/htp.h +++ b/htp/htp.h @@ -221,6 +221,8 @@ struct htp_tx_t { */ int is_config_shared; + SCAN_BUILD_X64_PADDING(int pad0;) + /** The user data associated with this transaction. */ void *user_data; @@ -230,6 +232,8 @@ struct htp_tx_t { /** Contains a count of how many empty lines were skipped before the request line. */ unsigned int request_ignored_lines; + SCAN_BUILD_X64_PADDING(int pad1;) + /** The first line of this request. */ bstr *request_line; @@ -239,6 +243,8 @@ struct htp_tx_t { /** Request method, as number. Available only if we were able to recognize the request method. */ enum htp_method_t request_method_number; + SCAN_BUILD_X64_PADDING(int pad2;) + /** * Request URI, raw, as given to us on the request line. This field can take different forms, * for example authority for CONNECT methods, absolute URIs for proxy requests, and the query @@ -421,6 +427,8 @@ struct htp_tx_t { */ int response_protocol_number; + SCAN_BUILD_X64_PADDING(int pad3;) + /** * Response status code, as text. Starts as NULL and can remain NULL on * an invalid response that does not specify status code. @@ -445,6 +453,8 @@ struct htp_tx_t { /** Have we seen the server respond with a 100 response? */ int seen_100continue; + SCAN_BUILD_X64_PADDING(int pad4;) + /** Parsed response headers. Contains instances of htp_header_t. */ htp_table_t *response_headers; @@ -512,6 +522,8 @@ struct htp_tx_t { */ enum htp_content_encoding_t response_content_encoding_processing; + SCAN_BUILD_X64_PADDING(int pad5;) + /** * This field will contain the response content type when that information * is available in response headers. The contents of the field will be converted diff --git a/htp/htp_core.h b/htp/htp_core.h index 7c23212a..d07f9913 100644 --- a/htp/htp_core.h +++ b/htp/htp_core.h @@ -43,6 +43,57 @@ extern "C" { #endif +/* Define SCAN_BUILD_X64_PADDING to add padding to structs for + * when clang scan-build is used with the optin.performance.Padding + * checker. */ +#if defined(__clang_analyzer__) +/** FreeBSD does not define __WORDSIZE, but it uses __LONG_BIT */ +#ifndef __WORDSIZE + #ifdef __LONG_BIT + #define __WORDSIZE __LONG_BIT + #else + #ifdef LONG_BIT + #define __WORDSIZE LONG_BIT + #endif + #endif +#endif + +/** Windows does not define __WORDSIZE, but it uses __X86__ */ +#ifndef __WORDSIZE + #if defined(__X86__) || defined(_X86_) || defined(_M_IX86) + #define __WORDSIZE 32 + #else + #if defined(__X86_64__) || defined(_X86_64_) || \ + defined(__x86_64) || defined(__x86_64__) || \ + defined(__amd64) || defined(__amd64__) + #define __WORDSIZE 64 + #endif + #endif +#endif + +/** if not succesful yet try the data models */ +#ifndef __WORDSIZE + #if defined(_ILP32) || defined(__ILP32__) + #define __WORDSIZE 32 + #endif + #if defined(_LP64) || defined(__LP64__) + #define __WORDSIZE 64 + #endif +#endif + +#ifndef __WORDSIZE + #define __WORDSIZE 64 +#endif + +#if __WORDSIZE==64 +#define SCAN_BUILD_X64_PADDING(x) x +#else +#define SCAN_BUILD_X64_PADDING(_x) +#endif +#else /* else __clang_analyzer__ */ +#define SCAN_BUILD_X64_PADDING(_x) +#endif /* end __clang_analyzer__ */ + typedef int htp_status_t; typedef struct htp_cfg_t htp_cfg_t;