Skip to content

Commit 636b53e

Browse files
committed
Add safe version of set_match_to_tx() (pass variable's length)
1 parent 0c49529 commit 636b53e

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

apache2/msc_util.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,9 @@ int convert_to_int(const char c)
537537
* \param msr Pointer to modsec resource
538538
* \param capture If ON match will be saved
539539
* \param match Pointer to captured string
540-
*\parm tx_n The tx number to save the data
540+
* \param tx_n The tx number to save the data
541541
*
542-
* \retval 0 On Sucess|Fail
542+
* \retval 0 On sucess
543543
*/
544544
int set_match_to_tx(modsec_rec *msr, int capture, const char *match, int tx_n) {
545545
assert(msr != NULL);
@@ -567,6 +567,41 @@ int set_match_to_tx(modsec_rec *msr, int capture, const char *match, int tx_n)
567567
}
568568

569569

570+
/** \brief Set a match to tx.N safe mode
571+
*
572+
* \param msr Pointer to modsec resource
573+
* \param capture If ON match will be saved
574+
* \param match Pointer to captured string
575+
* \param match_len Length of the captured string even if it contains NUL bytes
576+
* \param tx_n The tx number to save the data
577+
*
578+
* \retval 0 On sucess
579+
*/
580+
int set_match_to_tx_safe(modsec_rec *msr, int capture, const char *match, unsigned int match_len, int tx_n) {
581+
assert(msr != NULL);
582+
583+
if (capture) {
584+
msc_string *s = (msc_string *)apr_pcalloc(msr->mp, sizeof(msc_string));
585+
586+
if (s == NULL) return -1;
587+
588+
s->name = apr_psprintf(msr->mp,"%d", tx_n);
589+
s->name_len = strlen(s->name);
590+
s->value = apr_pstrmemdup(msr->mp, match, match_len);
591+
if (s->value == NULL) return -1;
592+
s->value_len = match_len;
593+
apr_table_setn(msr->tx_vars, s->name, (void *)s);
594+
595+
if (msr->txcfg->debuglog_level >= 9) {
596+
msr_log(msr, 9, "Added phrase match to TX.%d: %s",
597+
tx_n, log_escape_nq_ex(msr->mp, s->value, s->value_len));
598+
}
599+
600+
}
601+
602+
return 0;
603+
}
604+
570605
/**
571606
* Parses a string that contains a name-value pair in the form "name=value".
572607
* IMP1 It does not check for whitespace between tokens.

apache2/msc_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ int DSOLOCAL convert_to_int(const char c);
121121

122122
int DSOLOCAL set_match_to_tx(modsec_rec *msr, int capture, const char *match, int tx_n);
123123

124+
int DSOLOCAL set_match_to_tx_safe(modsec_rec *msr, int capture, const char *match, unsigned int match_len, int tx_n);
125+
124126
int DSOLOCAL js_decode_nonstrict_inplace(unsigned char *input, long int input_len);
125127

126128
int DSOLOCAL urldecode_uni_nonstrict_inplace_ex(unsigned char *input, long int input_length, int * changed);

0 commit comments

Comments
 (0)