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

Generalise development build options, and add --enable-devel-streamcheck #1887

Merged
merged 5 commits into from
May 28, 2021

Conversation

matt335672
Copy link
Member

This [draft] PR which adds a new development-only option --enable-streamcheck

Essentially it adds a check after every stream operation in parse.h that all is working as expected. If not a dump is taken. So it will impact performance, but should let us catch and find stream violations relatively easily during development. I'm not intending for this to be used at runtime!

It seemed to me it would be useful when working on #1885.

I've found a few gremlins already which I'm working through so this isn't yet ready. However, at this stage I'd appreciate any thoughts people have on this.

Copy link
Contributor

@aquesnel aquesnel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @matt335672

This looks good. I'd also suggest adding the sanitize compile flags to catch more memory errors. Here's my attempt at adding the sanitize flags: aquesnel@27a0eaf

@@ -58,6 +58,7 @@ libcommon_la_SOURCES = \
log.h \
os_calls.c \
os_calls.h \
parse.c \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse.c file is missing from this commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Should be there now!

@Nexarian
Copy link
Contributor

Might I suggest taking a page from FreeRDP's book: https://github.com/FreeRDP/FreeRDP/blob/master/cmake/ConfigOptions.cmake#L100

Essentially: Options that are for debugging are explicitly labeled so, and you also have the ability to toggle all debug options.

@matt335672
Copy link
Member Author

Thanks for that.

I like the idea a lot, but we already have the --enable-xrdpdebug option which does the following (AFAICT):-

  • Adds extra checking and logging to the embedded pixman code.
  • Defines the LOG_DEVEL() etc macros to do something interesting
  • Replaces the compiler flag -O2 with -g -O0.

So my question is; how do we get from where we are to where we want to be?

One idea is just to use a single --enable-xrdpdebug flag for everything. I'm not keen on this, as the checking above, and also @aquesnel's sanitise suggestion cause program exits when they find problems. This might be OK when everything is bedded in, but it will take a while to get there I think. Or am I being too critical?

Here's an other idea, which can be improved on I'm sure.

  • Rename --enable-xrdp-debug as --enable-debug-logging (I'm not so bothered about renaming a developer-only option)
  • Rename the option above to --enable-debug-stream
  • Add a --enable-debug-all to enable all debug options. Or re-use the --enable-xrdpdebug flag for this.
  • If any debug option is enabled, that sets compiler debug flags.

This is more disruptive but gives an extensible system it should be easy to plug other things into (e.g. the sanitize options).

Thoughts, anyone?

@aquesnel
Copy link
Contributor

I agree with your suggestion to split up the debug config flags.

@metalefty
Copy link
Member

I'm not so bothered about renaming a developer-only option

I agree.

@matt335672 matt335672 force-pushed the stream_overflow_check branch from da0e021 to b866fd6 Compare May 19, 2021 10:51
@matt335672
Copy link
Member Author

Thanks to all for comments. This is now ready for review. I've split it into 5 commits:-

  1. Split the existing --enable-xrdpdebug into --enable-devel-all, --enable-devel-debug, --enable-devel-logging.
  2. Add the additional --enable-devel-streamcheck option.
  3. Fix some unterminated buffer problems in the xrdp file I/O code found by --enable-devel-streamcheck. There's a one-liner to sesman in here too which dosn't warrant a separate commit.
  4. Fix a couple of minor problems in the RDP layer in librdp. One was a too-small size, and the other was an unitialised sec_hdr pointer which caused an out-of-bounds (but unused) pointer when the stream was compressed.
  5. Add some stream terminations to chansrv

Configure options are now as follows:-

Option Meaning
--enable-devel-debug Ensures executables are optimised for a debugger
--enable-devel-logging Mostly enables the LOG_DEVEL() etc macros
--enable-devel-streamcheck Forces range-checking on all stream operations
--enable-devel-all Enables all development options

The way it's set up means that combinations like ./configure --enable-devel-all --disable-devel-streamcheck work if you just want to disable a single feature which is giving you trouble.

I've moved the necessary pre-processor options into config_ac.h, which means I've removed a lot of these kind of stanzas from Makefile.am files:-

if XRDP_DEBUG
AM_CPPFLAGS += -DXRDP_DEBUG
endif

I haven't added @aquesnel's suggested sanitiser calls yet, but it should be trivial to do so. Maybe a separate commit?

@matt335672 matt335672 marked this pull request as ready for review May 19, 2021 11:19
@matt335672 matt335672 changed the title Add --enable-streamcheck Generalise development build options, and add --enable-devel-streamcheck May 19, 2021
@aquesnel
Copy link
Contributor

I'd say that we can add the sanitize flags later in a separate PR.
What are the next steps to get this PR merged?

@matt335672 matt335672 force-pushed the stream_overflow_check branch from b866fd6 to eda01f0 Compare May 28, 2021 09:57
@matt335672
Copy link
Member Author

I could really do with this for testing the stuff I've got in #1900. Since it's developer-only I'll merge it now.

@matt335672 matt335672 merged commit 7d8f084 into neutrinolabs:devel May 28, 2021
matt335672 added a commit that referenced this pull request Jun 2, 2021
Fixes --enable-devel-streamcheck (update to #1887)
@matt335672 matt335672 deleted the stream_overflow_check branch June 16, 2021 09:52
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

Successfully merging this pull request may close these issues.

4 participants