Skip to content

Commit ad1f5d6

Browse files
committed
fix potential parsing of undefined data is syslog probe and make probe more robust
1 parent ff8206f commit ad1f5d6

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

probe.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define PCRE2_CODE_UNIT_WIDTH 8
2626
#include <pcre2.h>
2727
#endif
28+
#include <regex.h>
2829
#include <ctype.h>
2930
#include "probe.h"
3031
#include "log.h"
@@ -362,17 +363,38 @@ static int is_socks5_protocol(const char *p_in, ssize_t len, struct sslhcfg_prot
362363
return PROBE_MATCH;
363364
}
364365

366+
/* ******************
367+
* is_syslog_protocol
368+
* */
369+
static regex_t syslog_preg;
370+
static int configured_syslog_regex = 0;
371+
372+
static void config_syslog_regex(void)
373+
{
374+
/* two patterns for syslog messages:
375+
* <12> My message
376+
* 15 <12> My message
377+
* 12 is 'priority', 1 to 3 digits (RFC4234)
378+
* 15 is 'message length', a TCP-only option (RFC6587)
379+
*/
380+
int res = regcomp(&syslog_preg, "^([0-9]{1,3} )?<[0-9]{1,3}>", REG_EXTENDED);
381+
if (res) {
382+
print_message(msg_system_error, "regcomp");
383+
exit(1);
384+
}
385+
configured_syslog_regex = 1;
386+
}
387+
365388
static int is_syslog_protocol(const char *p, ssize_t len, struct sslhcfg_protocols_item* proto)
366389
{
367-
int res, i, j;
390+
char buf[len+1];
368391

369-
res = sscanf(p, "<%d>", &i);
370-
if (res == 1) return PROBE_MATCH;
392+
if (!configured_syslog_regex) config_syslog_regex();
371393

372-
res = sscanf(p, "%d <%d>", &i, &j);
373-
if (res == 2) return PROBE_MATCH;
394+
strncpy(buf, p, len);
395+
buf[len] = 0;
374396

375-
return PROBE_NEXT;
397+
return (regexec(&syslog_preg, buf, (size_t)0, NULL, 0) == 0);
376398
}
377399

378400
static int is_teamspeak_protocol(const char *p, ssize_t len, struct sslhcfg_protocols_item* proto)

0 commit comments

Comments
 (0)