-
Notifications
You must be signed in to change notification settings - Fork 835
SEGFAULT in cfg_parse_peers() #2872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi WhiteWLf-dev , Thanks for your report ! In order to gather more info: do you use some custom build for this test ? I'm asking this, because you've reported the version 3.2-dev5. Normally, with this version, stack trace should be ( from main() -> to cfg_parse_peers())
Thanks in advance, |
I've reproduced on my side with "unmodified" official dev release. Indeed this segfaults with your config example. Thanks for the report ! |
This patch below should fix this crash:
I think the best solution here is to stop the parser immediately with ERR_ABORT, instead of accumulating ERR_FATAL and try to parse "peer" keywords within the wrongly declared "peers" section, because we may have more than one "peers" section and by this we may risk to associate a peer "haproxy4" with a wrong section "mypeers".
In addition, if we will just signal "peers yet_another some_garbage_" by an alert at start and won't parse its contents, haproxy can start anyway with such buggy conf (number of fatal errors < 50). |
So did you try delete one symbol on first line? The problem will be disappeared and I can't understand why. Definitely, it depends on size of some buffers (for trash and etc) and I can't detect type of the buffer and where it's placed. @einval22 |
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions.
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue #2872. This should be backported in all stable versions.
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit f595db1) Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit f595db1) Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com> (cherry picked from commit a864292) Signed-off-by: Willy Tarreau <w@1wt.eu>
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu>
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit f595db1) Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com> (cherry picked from commit a864292) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com>
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue #2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit f595db1) Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com> (cherry picked from commit a864292) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com> (cherry picked from commit 4ebda48) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com>
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit f595db1) Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com> (cherry picked from commit a864292) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com> (cherry picked from commit 4ebda48) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com> (cherry picked from commit 62651b9) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com>
When "peers" keyword is followed by more than one argument and it's the first "peers" section in the config, cfg_parse_peers() detects it and exits with "ERR_ALERT|ERR_FATAL" err_code. So, upper layer parser, parse_cfg(), continues and parses the next keyword "peer" and then he tries to check the global cfg_peers, which should contain "my_cluster". The global cfg_peers is still NULL, because after alerting a user in alertif_too_many_args, cfg_parse_peers() exited. peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In order to fix this, let's add ERR_ABORT, if "peers" keyword is followed by more than one argument. Like this parse_cfg() will stops immediately and terminates haproxy with "too many args for peers my_cluster..." alert message. It's more reliable, than add checks "if (cfg_peers !=NULL)" in "peer" subparser, as we may have many "peers" sections. peers my_another_cluster peer haproxy1 1.1.1.2 1000 peers my_cluster __some_wrong_data__ peer haproxy1 1.1.1.1 1000 In addition, for the example above, parse_cfg() will parse all configuration until the end and only then terminates haproxy with the alert "too many args...". Peer haproxy1 will be wrongly associated with my_another_cluster. This fixes the issue haproxy#2872. This should be backported in all stable versions. (cherry picked from commit 390df28) Signed-off-by: Willy Tarreau <w@1wt.eu> (cherry picked from commit f595db1) Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com> (cherry picked from commit a864292) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com> (cherry picked from commit 4ebda48) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com> (cherry picked from commit 62651b9) Signed-off-by: Aurelien DARRAGON <adarragon@haproxy.com> (cherry picked from commit c16b5bf) Signed-off-by: Willy Tarreau <w@1wt.eu>
Detailed Description of the Problem
When I give mycfg.cfg file to haproxy with -f args, I got SEGFAULT.
[New Thread 0x7ffff71ff6c0 (LWP 3688482)]
[Thread 0x7ffff71ff6c0 (LWP 3688482) exited]
[NOTICE] (3688479) : haproxy version is 3.2-dev5
[NOTICE] (3688479) : path to executable is /home/as/projects/upstream/newhaproxy/haproxy/haproxy
[ALERT] (3688479) : config : parsing [tt:1]: unknown keyword '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' out of section.
[ALERT] (3688479) : config : parsing [tt:3] : 'peers' cannot handle unexpected argument '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'.
Thread 1 "haproxy" received signal SIGSEGV, Segmentation fault.
0x000055555570450a in cfg_parse_peers (file=0x555555be0d10 "tt", linenum=4, args=0x7fffffffd850, kwm=) at src/cfgparse.c:850
850 if (cfg_peers->local && !cfg_peers->local->id && local_peer) {
(gdb) bt
#0 0x000055555570450a in cfg_parse_peers (file=0x555555be0d10 "tt", linenum=4, args=0x7fffffffd850, kwm=) at src/cfgparse.c:850
#1 0x0000555555706a77 in parse_cfg (cfg=cfg@entry=0x555555bdef00) at src/cfgparse.c:2621
#2 0x0000555555764e52 in read_cfg () at src/haproxy.c:1010
#3 0x00005555555c7f8b in main (argc=, argv=) at src/haproxy.c:3215
Expected Behavior
Error message without SEGFAULT.
Steps to Reproduce the Behavior
Run haproxy as:
./haproxy -f mycfg.txt
mycfg1.txt
Do you have any idea what may have caused this?
No response
Do you have an idea how to solve the issue?
if (!cfg_peers) {
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}
if (cfg_peers->local && !cfg_peers->local->id && local_peer) {
What is your configuration?
Output of
haproxy -vv
Last Outputs and Backtraces
Additional Information
No response
The text was updated successfully, but these errors were encountered: