Skip to content
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

Unbound Segmentation Fault w/ log_info Functions From Python Mod #333

Closed
drachs opened this issue Oct 21, 2020 · 1 comment
Closed

Unbound Segmentation Fault w/ log_info Functions From Python Mod #333

drachs opened this issue Oct 21, 2020 · 1 comment

Comments

@drachs
Copy link

drachs commented Oct 21, 2020

log_info is a C function that takes printf style variadic arguments as a parameter. SWIG by default does not wrap variadic arguments. It always calls log_info as:

log_info(param1, NULL)

This means that all string parameters have to be cooked down into param1. This is the python way of doing things, so it itself is not a problem. However '%' is a special character in printf, and cannot be sent safely in the first parameter. Therefore, no user data is safe to use with this logger by default.

For purpose of example, the following line will segmentation fault unbound when called from operate:

log_info("CRASH %s CRASH" % ("%40n"))

I think log_info and related functions exposed to python should be replaced with a stub that calls

log_info("%s", input)

We worked around this problem with the following python code:

def log(value):
    unbound_log_info(value.replace("%", "%%"))

unbound_log_info = log_info
log_info = log
log_err = log
log_warn = log

@wcawijngaards
Copy link
Member

Thanks for the report! Fixed it by providing one string argument log functions, like you suggested. Also for verbose(level, string), log_err, and log_warn, aside from log_info. The original functions are still available as unbound_log_info, unbound_log_err and so on.

jedisct1 added a commit to jedisct1/unbound that referenced this issue Nov 1, 2020
* nlnet/master: (81 commits)
  - In man page note that tls-cert-bundle is read before permission   drop and chroot.
  - Fix that minimal-responses does not remove addresses from a priming   query response.
  - Fix NLnetLabs#333: Unbound Segmentation Fault w/ log_info Functions From   Python Mod.
  - Fix NLnetLabs#320: potential memory corruption due to size miscomputation upton   custom region alloc init.
  - Fix NLnetLabs#327: net/if.h check fails on some darwin versions; contribution by   Joshua Root.
  Add verbosity to debug occasional missing q1-10.example.net, from timer.
  Changelog note for NLnetLabs#228 - Merge PR NLnetLabs#228 : infra-keep-probing option to probe hosts that are   down.  Add infra-keep-probing: yes option. Hosts that are down are   probed more frequently.   With the option turned on, it probes about every 120 seconds,   eventually after exponential backoff, and that keeps that way. If   traffic keeps up for the domain. It probes with one at a time, eg.   one query is allowed to probe, other queries within that 120 second   interval are turned away.
  - Changelog entry for PR NLnetLabs#324: Add modern X.509v3 extensions to   unbound-control TLS certificates, by James Renken.
  - Fix for attaching the X509v3 extensions to the client certificate.
  - Clean the fix for out of order TCP processing limits on number   of queries.  It was tested to work.
  Fixup for clear of tcp handler structure.
  - Fix to set the tcp handler event toggle flag back to default when   the handler structure is reused.
  Changelog entry for local-zone out of chunk regional allocation
  - Log ip address when http session recv fails, eg. due to tls fail.
  Unit test for doh downstream notls.
  - Fix dnstap test to wait for log timer to see if queries are logged.
  - Fix python documentation warning on functions.rst inplace_cb_reply.
  - Fix NLnetLabs#330: [Feature request] Add unencrypted DNS over HTTPS support.   This adds the option http-notls-downstream: yesno to change that,   and the dohclient test code has the -n option.
  - Fix memory leak of https port string when reading config.
  - Fix that http settings have colon in set_option, for   http-endpoint, http-max-streams, http-query-buffer-size,   http-response-buffer-size, and http-nodelay.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants