Skip to content

Commit 82c5c3a

Browse files
committed
Fix compiler warnings. Reported by GCC with flags:
-Wall -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS Note, e.g. sprintf(digest, "%s%02x", digest, ...) is undefined behaviour because the destination and source variables overlap, and GCC warnings for this. acmp.c:258:13: warning: 'acmp_clone_node_no_state' defined but not used [-Wunused-function] apache2_config.c:806:9: warning: unused variable 'offset' [-Wunused-variable] apache2_config.c:1886:23: warning: unused variable 'dcfg' [-Wunused-variable] apache2_config.c:1942:23: warning: unused variable 'dcfg' [-Wunused-variable] apache2_config.c:2470:23: warning: unused variable 'dcfg' [-Wunused-variable] apache2_config.c:2538:23: warning: unused variable 'dcfg' [-Wunused-variable] apache2_util.c:226:11: warning: unused variable 'str' [-Wunused-variable] apache2_util.c:225:11: warning: unused variable 'saved' [-Wunused-variable] apache2_util.c:224:11: warning: unused variable 'parse_remote' [-Wunused-variable] apache2_util.c:223:11: warning: unused variable 'remote' [-Wunused-variable] msc_status_engine.c:216:17: warning: unused variable 'i' [-Wunused-variable] msc_status_engine.c:375:55: warning: the address of 'pcre' will always evaluate as 'true' [-Waddress] msc_crypt.c:67:17: warning: unused variable 'bytes' [-Wunused-variable] msc_crypt.c:1083:33: warning: variable 'enc' set but not used [-Wunused-but-set-variable] msc_crypt.c:1090:29: warning: variable 'enc' set but not used [-Wunused-but-set-variable] /usr/include/bits/stdio2.h:30:10: warning: '__sprintf_chk' argument 5 overlaps destination object 'digest' [-Wrestrict] msc_json.c:405:11: warning: unused variable 'json_data' [-Wunused-variable] msc_crypt.c:1097:79: warning: '%s' directive argument is null [-Wformat-overflow=] msc_logging.c:1144:20: warning: unused variable 'now' [-Wunused-variable] msc_remote_rules.c:729:19: warning: unused variable 'word' [-Wunused-variable] msc_remote_rules.c:727:17: warning: unused variable 'tmp' [-Wunused-variable] msc_remote_rules.c:805:1: warning: control reaches end of non-void function [-Wreturn-type] msc_tree.c:836:19: warning: unused variable 'ip' [-Wunused-variable] msc_xml.c:29:44: warning: variable 'entity' set but not used [-Wunused-but-set-variable] msc_util.c:2627:11: warning: unused variable 'start' [-Wunused-variable] msc_util.c:2626:17: warning: unused variable 'fd' [-Wunused-variable] msc_util.c:2624:18: warning: unused variable 'rc' [-Wunused-variable] msc_util.c:1077:19: warning: array subscript 1 is outside array bounds of 'unsigned char[1]' [-Warray-bounds=]
1 parent 1a2de10 commit 82c5c3a

14 files changed

+13
-65
lines changed

apache2/acmp.c

+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ static void acmp_add_node_to_parent(acmp_node_t *parent, acmp_node_t *child) {
251251
}
252252
}
253253

254+
#if 0
254255
/**
255256
* Copies values from one node to another, without child/sibling/fail pointers
256257
* and without state variables.
@@ -262,6 +263,7 @@ static void acmp_clone_node_no_state(acmp_node_t *from, acmp_node_t *to) {
262263
to->fail = NULL;
263264
to->hit_count = 0;
264265
}
266+
#endif
265267

266268
static inline acmp_node_t *acmp_btree_find(acmp_node_t *node, acmp_utf8_char_t letter) {
267269
acmp_btree_node_t *bnode = node->btree;

apache2/apache2_config.c

-5
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
797797
int type_with_lua = 1;
798798
int type_rule;
799799
int rule_actionset;
800-
int offset = 0;
801800

802801
#ifdef DEBUG_CONF
803802
ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_NOERRNO, 0, cmd->pool,
@@ -1935,7 +1934,6 @@ static const char *cmd_conn_read_state_limit(cmd_parms *cmd, void *_dcfg,
19351934
ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, cmd->pool, "cmd_conn_read_state_limit: _dcfg is NULL");
19361935
return NULL;
19371936
}
1938-
directory_config *dcfg = (directory_config *)_dcfg;
19391937
long int limit;
19401938

19411939
limit = strtol(p1, NULL, 10);
@@ -1991,7 +1989,6 @@ static const char *cmd_conn_write_state_limit(cmd_parms *cmd, void *_dcfg,
19911989
ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, cmd->pool, "cmd_conn_write_state_limit: _dcfg is NULL");
19921990
return NULL;
19931991
}
1994-
directory_config *dcfg = (directory_config *)_dcfg;
19951992
long int limit;
19961993

19971994
limit = strtol(p1, NULL, 10);
@@ -2519,7 +2516,6 @@ static const char *cmd_sever_conn_filters_engine(cmd_parms *cmd, void *_dcfg,
25192516
ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, cmd->pool, "cmd_sever_conn_filters_engine: _dcfg is NULL");
25202517
return NULL;
25212518
}
2522-
directory_config *dcfg = (directory_config *)_dcfg;
25232519

25242520
if (strcasecmp(p1, "on") == 0)
25252521
{
@@ -2587,7 +2583,6 @@ static const char *cmd_remote_rules_fail(cmd_parms *cmd, void *_dcfg, const char
25872583
ap_log_perror(APLOG_MARK, APLOG_EMERG, 0, cmd->pool, "cmd_remote_rules_fail: _dcfg is NULL");
25882584
return NULL;
25892585
}
2590-
directory_config *dcfg = (directory_config *)_dcfg;
25912586

25922587
if (strncasecmp(p1, "warn", 4) == 0)
25932588
{

apache2/apache2_util.c

-4
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ static void internal_log_ex(request_rec *r, directory_config *dcfg, modsec_rec *
215215
apr_size_t nbytes, nbytes_written;
216216
apr_file_t *debuglog_fd = NULL;
217217
int filter_debug_level = 0;
218-
char *remote = NULL;
219-
char *parse_remote = NULL;
220-
char *saved = NULL;
221-
char *str = NULL;
222218
char str1[1024] = "";
223219
char str2[1256] = "";
224220

apache2/msc_crypt.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ char *normalize_path(modsec_rec *msr, char *input) {
6464

6565
if(uri->path) {
6666
char *Uri = NULL;
67-
int bytes = 0;
6867
/*int i;*/
6968
char *abs_link = NULL;
7069
char *filename = NULL;
@@ -1079,22 +1078,18 @@ int inject_hashed_response_body(modsec_rec *msr, int elts) {
10791078
if (ctype && encoding == NULL) {
10801079
if (ctype && (p = m_strcasestr(ctype, "charset=") , p != NULL)) {
10811080
p += 8 ;
1082-
if (encoding = apr_pstrndup(msr->mp, p, strcspn(p, " ;") ), encoding) {
1083-
xmlCharEncoding enc;
1084-
enc = xmlParseCharEncoding(encoding);
1085-
handler = xmlFindCharEncodingHandler(encoding);
1086-
}
1081+
encoding = apr_pstrndup(msr->mp, p, strcspn(p, " ;"));
1082+
handler = xmlFindCharEncodingHandler(encoding);
10871083
}
10881084
} else {
10891085
if(encoding != NULL) {
1090-
xmlCharEncoding enc;
1091-
enc = xmlParseCharEncoding(encoding);
10921086
handler = xmlFindCharEncodingHandler(encoding);
10931087
}
10941088
}
10951089

10961090
if (msr->txcfg->debuglog_level >= 4)
1097-
msr_log(msr, 4, "inject_hashed_response_body: Detected encoding type [%s].", encoding);
1091+
msr_log(msr, 4, "inject_hashed_response_body: Detected encoding type [%s].",
1092+
encoding ? encoding : "(none)");
10981093

10991094
if (handler == NULL)
11001095
handler = xmlFindCharEncodingHandler("UTF-8");

apache2/msc_geo.c

-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ int geo_lookup(modsec_rec *msr, geo_rec *georec, const char *target, char **erro
279279
apr_size_t nbytes;
280280
unsigned int rec_val = 0;
281281
apr_off_t seekto = 0;
282-
apr_status_t ret;
283282
int rc;
284283
int country = 0;
285284
int level;

apache2/msc_json.c

-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ int json_complete(modsec_rec *msr, char **error_msg) {
402402
assert(msr != NULL);
403403
assert(msr->json != NULL);
404404
assert(error_msg != NULL);
405-
char *json_data = (char *) NULL;
406405

407406
*error_msg = NULL;
408407

apache2/msc_logging.c

-2
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,6 @@ void sec_audit_logger_json(modsec_rec *msr) {
11341134
/* AUDITLOG_PART_TRAILER */
11351135

11361136
if (strchr(msr->txcfg->auditlog_parts, AUDITLOG_PART_TRAILER) != NULL) {
1137-
apr_time_t now = apr_time_now();
1138-
11391137
/* Messages */
11401138
been_opened = 0;
11411139
if (msr->alerts->nelts > 0) {

apache2/msc_remote_rules.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,7 @@ int msc_remote_add_rules_from_uri(cmd_parms *orig_parms,
719719
if (plain_text[len] == '\n')
720720
{
721721
const char *rule = NULL;
722-
int tmp = len;
723722
char *cmd_name = NULL;
724-
char *word = NULL;
725723
const command_rec *cmd;
726724

727725
ap_directive_t *newdir;
@@ -792,6 +790,7 @@ int msc_remote_add_rules_from_uri(cmd_parms *orig_parms,
792790
{
793791
msc_remote_clean_chunk(&downloaded_content);
794792
}
793+
return 0;
795794
#else
796795
*error_msg = "SecRemoteRules was not enabled during ModSecurity " \
797796
"compilation.";

apache2/msc_status_engine.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ int DSOLOCAL msc_status_engine_mac_address (unsigned char *mac)
164164
#ifdef DARWIN
165165
struct ifaddrs* ifaphead;
166166
struct ifaddrs* ifap;
167-
int i = 0;
168167

169168
if ( getifaddrs( &ifaphead ) != 0 ) {
170169
goto failed;
@@ -213,7 +212,6 @@ int DSOLOCAL msc_status_engine_mac_address (unsigned char *mac)
213212
}
214213

215214
if ( ioctl( sock, SIOCGIFHWADDR, ifr ) == 0 ) {
216-
int i = 0;
217215
if (!ifr->ifr_addr.sa_data[0] && !ifr->ifr_addr.sa_data[1]
218216
&& !ifr->ifr_addr.sa_data[2]) {
219217
continue;
@@ -290,7 +288,6 @@ int DSOLOCAL msc_status_engine_unique_id (unsigned char *digest)
290288
unsigned char *mac_address = NULL;
291289
char *machine_name = NULL;
292290
int ret = 0;
293-
int i = 0;
294291
apr_sha1_ctx_t context;
295292

296293
mac_address = malloc(sizeof(char)*(MAC_ADDRESS_SIZE));
@@ -321,10 +318,7 @@ int DSOLOCAL msc_status_engine_unique_id (unsigned char *digest)
321318
apr_sha1_update(&context, mac_address, strlen(mac_address));
322319
apr_sha1_final(hex_digest, &context);
323320

324-
for (i = 0; i < APR_SHA1_DIGESTSIZE; i++)
325-
{
326-
sprintf(digest, "%s%02x", digest, hex_digest[i]);
327-
}
321+
ap_bin2hex(hex_digest, APR_SHA1_DIGESTSIZE, digest);
328322

329323
failed_set_machine_name:
330324
free(machine_name);
@@ -372,7 +366,7 @@ int DSOLOCAL msc_beacon_string (char *beacon_string, int beacon_string_max_len)
372366
/* 6 represents: strlen("(null)") */
373367
beacon_string_len = (modsec ? strlen(modsec) : 6) +
374368
(apache ? strlen(apache) : 6) + (apr ? strlen(apr) : 6) +
375-
(apr_loaded ? strlen(apr_loaded) : 6) + (pcre ? strlen(pcre) : 6) +
369+
(apr_loaded ? strlen(apr_loaded) : 6) + strlen(pcre) +
376370
(pcre_loaded ? strlen(pcre_loaded) : 6) + (lua ? strlen(lua) : 6) +
377371
(libxml ? strlen(libxml) : 6) + (APR_SHA1_DIGESTSIZE * 2);
378372

apache2/msc_tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ TreeNode *CPTIpMatch(modsec_rec *msr, unsigned char *ipdata, CPTTree *tree, int
833833
}
834834

835835
TreeNode *TreeAddIP(const char *buffer, CPTTree *tree, int type) {
836-
unsigned long ip, ret;
836+
unsigned long ret;
837837
unsigned char netmask_v4 = NETMASK_32, netmask_v6 = NETMASK_128;
838838
char ip_strv4[NETMASK_32], ip_strv6[NETMASK_128];
839839
struct in_addr addr4;

apache2/msc_util.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,12 @@ int swap_int32(int x) {
104104
* \retval rval On Success
105105
*/
106106
char *utf8_unicode_inplace_ex(apr_pool_t *mp, unsigned char *input, long int input_len, int *changed) {
107-
int unicode_len = 0, length = 0;
107+
int unicode_len = 0;
108108
unsigned int d = 0;
109109
unsigned char c, *utf;
110110
char *rval, *data;
111-
unsigned int i, len, j;
111+
unsigned int i, len;
112112
unsigned int bytes_left = input_len;
113-
unsigned char *unicode = NULL;
114113

115114
assert(input != NULL);
116115

@@ -2497,10 +2496,7 @@ int ip_tree_from_uri(TreeRoot **rtree, char *uri,
24972496
apr_pool_t *mp, char **error_msg)
24982497
{
24992498
TreeNode *tnode = NULL;
2500-
apr_status_t rc;
25012499
int line = 0;
2502-
apr_file_t *fd;
2503-
char *start;
25042500
int res;
25052501

25062502
struct msc_curl_memory_buffer_t chunk;

apache2/msc_xml.c

-10
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,19 @@ static void msc_xml_on_characters(void *ctx, const xmlChar *ch, int len) {
132132
}
133133

134134

135-
static xmlParserInputBufferPtr
136-
xml_unload_external_entity(const char *URI, xmlCharEncoding enc) {
137-
return NULL;
138-
}
139-
140135

141136
/**
142137
* Initialise XML parser.
143138
*/
144139
int xml_init(modsec_rec *msr, char **error_msg) {
145140
assert(msr != NULL);
146141
assert(error_msg != NULL);
147-
xmlParserInputBufferCreateFilenameFunc entity;
148142

149143
*error_msg = NULL;
150144

151145
msr->xml = apr_pcalloc(msr->mp, sizeof(xml_data));
152146
if (msr->xml == NULL) return -1;
153147

154-
if(msr->txcfg->xml_external_entity == 0) {
155-
entity = xmlParserInputBufferCreateFilenameDefault(xml_unload_external_entity);
156-
}
157-
158148
if (msr->txcfg->parse_xml_into_args != MSC_XML_ARGS_OFF) {
159149

160150
msr->xml->sax_handler = (xmlSAXHandler *)apr_pcalloc(msr->mp, sizeof(xmlSAXHandler));

apache2/re.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,9 @@ char *msre_ruleset_phase_rule_update_target_matching_exception(modsec_rec *msr,
205205
assert(ruleset != NULL);
206206
assert(phase_arr != NULL);
207207
msre_rule **rules;
208-
int i, j, mode;
208+
int i, mode;
209209
char *err;
210210

211-
j = 0;
212211
mode = 0;
213212
rules = (msre_rule **)phase_arr->elts;
214213
for (i = 0; i < phase_arr->nelts; i++) {
@@ -247,7 +246,6 @@ char *update_rule_target_ex(modsec_rec *msr, msre_ruleset *ruleset, msre_rule *r
247246
char *my_error_msg = NULL, *target = NULL;
248247
char *p = NULL, *savedptr = NULL;
249248
unsigned int is_negated = 0, is_counting = 0;
250-
int name_len = 0, value_len = 0;
251249
char *name = NULL, *value = NULL;
252250
char *opt = NULL, *param = NULL;
253251
char *target_list = NULL, *replace = NULL;
@@ -297,10 +295,6 @@ char *update_rule_target_ex(modsec_rec *msr, msre_ruleset *ruleset, msre_rule *r
297295
goto end;
298296
}
299297

300-
name_len = strlen(name);
301-
302-
if (value != NULL) value_len = strlen(value);
303-
304298
targets = (msre_var **)rule->targets->elts;
305299
// TODO need a good way to remove the element from array, maybe change array by tables or rings
306300
for (i = 0; i < rule->targets->nelts; i++) {
@@ -395,10 +389,6 @@ char *update_rule_target_ex(modsec_rec *msr, msre_ruleset *ruleset, msre_rule *r
395389
goto end;
396390
}
397391

398-
name_len = strlen(name);
399-
400-
if (value != NULL) value_len = strlen(value);
401-
402392
if (msr) {
403393
msr_log(msr, 9, "Trying to append variable name [%s] value [%s]", name, value);
404394
}

apache2/re_operators.c

-5
Original file line numberDiff line numberDiff line change
@@ -4231,11 +4231,6 @@ static int msre_op_fuzzy_hash_init(msre_rule *rule, char **error_msg)
42314231
return 1;
42324232
#endif
42334233
return 1;
4234-
4235-
invalid_parameters:
4236-
*error_msg = apr_psprintf(rule->ruleset->mp, "Operator @fuzzyHash " \
4237-
"requires valid parameters. File and threshold.");
4238-
return -1;
42394234
}
42404235

42414236
static int msre_op_fuzzy_hash_execute(modsec_rec *msr, msre_rule *rule,

0 commit comments

Comments
 (0)