From 9a92dec1dcc618051500908a1f24761ab29abdcb Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 10 Jun 2024 20:36:22 -0700 Subject: [PATCH] tftpd: make it possible to adjust the remap deadman Allow the user to tweak the remap deadman counter if it is necessary for whatever reason. Signed-off-by: H. Peter Anvin --- tftpd/remap.c | 10 ++++++---- tftpd/remap.h | 3 +++ tftpd/tftpd.8.in | 4 ++++ tftpd/tftpd.c | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/tftpd/remap.c b/tftpd/remap.c index d74b2db..6497cad 100644 --- a/tftpd/remap.c +++ b/tftpd/remap.c @@ -39,6 +39,8 @@ #define RULE_WRQ 0x400 /* Put (write) only */ #define RULE_SEDG 0x800 /* sed-style global */ +int deadman_max_steps = DEADMAN_MAX_STEPS; + struct rule { struct rule *next; int nrule; @@ -397,7 +399,7 @@ char *rewrite_string(const struct formats *pf, int i; int len, newlen; int was_match = 0; - int deadman = DEADMAN_MAX_STEPS; + int deadman = deadman_max_steps; int matchsense; int pmatches; unsigned int bad_flags; @@ -534,9 +536,9 @@ char *rewrite_string(const struct formats *pf, return current; dead: /* Deadman expired */ - syslog(LOG_WARNING, - "remap: Breaking loop, input = %s, last = %s", input, - current); + syslog(LOG_ERR, + "remap: Breaking loop after %d steps, input = %s, last = %s", + deadman_max_steps, input, current); free(current); return NULL; /* Did not terminate! */ } diff --git a/tftpd/remap.h b/tftpd/remap.h index a9954ab..c8d76ff 100644 --- a/tftpd/remap.h +++ b/tftpd/remap.h @@ -40,5 +40,8 @@ char *rewrite_string(const struct formats *, const char *, const struct rule *, int, int, match_pattern_callback, const char **); +/* Remapping deadman counter */ +extern int deadman_max_steps; + #endif /* WITH_REGEX */ #endif /* TFTPD_REMAP_H */ diff --git a/tftpd/tftpd.8.in b/tftpd/tftpd.8.in index 9baf7fd..3d43325 100644 --- a/tftpd/tftpd.8.in +++ b/tftpd/tftpd.8.in @@ -163,6 +163,10 @@ remapping below. This option may not be compiled in, see the output of .B "in.tftpd \-V" to verify whether or not it is available. .TP +.\fB\-\-map-steps\fP \fIsteps\fP +Specify the number of remapping rules that may be executed before the +filename mapping fails. The default is 4096. +.TP \fB\-\-verbose\fP, \fB\-v\fP Increase the logging verbosity of .BR tftpd . diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index bec0f34..fc7e54a 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -325,6 +325,7 @@ static int split_port(char **ap, char **pp) enum long_only_options { OPT_VERBOSITY = 256, + OPT_MAP_STEPS }; static struct option long_options[] = { @@ -347,6 +348,7 @@ static struct option long_options[] = { { "retransmit", 1, NULL, 'T' }, { "port-range", 1, NULL, 'R' }, { "map-file", 1, NULL, 'm' }, + { "map-steps", 1, NULL, OPT_MAP_STEPS }, { "pidfile", 1, NULL, 'P' }, { NULL, 0, NULL, 0 } }; @@ -495,6 +497,18 @@ int main(int argc, char **argv) } rewrite_file = optarg; break; + case OPT_MAP_STEPS: + { + char *ep; + unsigned long steps = strtoul(optarg, &ep, 0); + if (*optarg && *ep && steps > 0 && steps <= INT_MAX) { + deadman_max_steps = steps; + } else { + syslog(LOG_ERR, "Bad --map-steps option: %s", optarg); + exit(EX_USAGE); + } + break; + } #endif case 'v': verbosity++; -- 2.11.4.GIT