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

Fix: Improve handling of very large arguments in the tracebld sample #83

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ScatteredRay
Copy link

There are two fixes here, the first fixes an off by one error in response file parsing that causes parsing it to fail. The second is an improvement to handle command line arguments that go over int16_max including xml tags and message padding.

…, we end up skipping past the beginning of the argument causing the rest to fail.
…uffer, we just send it over the line in fragments instead.
Copy link
Author

@ScatteredRay ScatteredRay left a comment

Choose a reason for hiding this comment

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

Added some comments about what this fixes.

@@ -4266,7 +4266,7 @@ PWCHAR LoadCommandLine(PCWSTR pwz, PWCHAR pwzDst, PWCHAR pwzDstEnd)
// More arguments!
WCHAR wzPath[MAX_PATH];
PWCHAR pwzPath = wzPath;
PCWSTR pwzTmp = pwzArgBeg + 1;
PCWSTR pwzTmp = pwzArgBeg;
Copy link
Author

Choose a reason for hiding this comment

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

This is a fix for an off-by-one error in response file parsing. Response file parsing doesn't work at all without this fix.

}
for(PWCHAR pwzTmp = pwzFin; pwzTmp < pwzFin + wcNew; pwzTmp += 32764) {
Copy link
Author

Choose a reason for hiding this comment

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

if pwzTmp is very large, it overflows the structure that passes this string to the host app. This solution sends it in parts.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this does what you think it does. The problem is that the characters in the string are being escaped. Some input characters require 6 characters in the output. This means that the output may require more than 32764 characters. if it does, some characters in the input string may not be written.

It is also not a good idea to embed a constant like 32764 here. This constant comes from tracebld.h, specifically the number of characters in szMessage in the definition of the struct _TBLOG_MESSAGE. In fact, looking at the code for VSafePrintf, it looks like one character is reserved for a null terminator (line 1880 in trcbld.cpp).

Copy link
Contributor

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

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

@ScatteredRay, thank for the fixes. The first fix for the off-by-one looks good. I think you need to revise how a large string is being broken into chunks.

}
for(PWCHAR pwzTmp = pwzFin; pwzTmp < pwzFin + wcNew; pwzTmp += 32764) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this does what you think it does. The problem is that the characters in the string are being escaped. Some input characters require 6 characters in the output. This means that the output may require more than 32764 characters. if it does, some characters in the input string may not be written.

It is also not a good idea to embed a constant like 32764 here. This constant comes from tracebld.h, specifically the number of characters in szMessage in the definition of the struct _TBLOG_MESSAGE. In fact, looking at the code for VSafePrintf, it looks like one character is reserved for a null terminator (line 1880 in trcbld.cpp).

@bgianfo bgianfo added the bug Something isn't working label Aug 21, 2020
@bgianfo
Copy link
Contributor

bgianfo commented Sep 6, 2020

@ScatteredRay Do you think you'll get some time to address @dtarditi's feedback?

@bgianfo bgianfo added the needs-author-feedback This issue / or pull request requires author feedback before more action can be taken. label Jan 24, 2021
@bgianfo
Copy link
Contributor

bgianfo commented Jan 24, 2021

Ping @ScatteredRay

@ScatteredRay
Copy link
Author

Hey bgianfo.

I do want to be able to address this and create a proper fix. I think I understand the issue, but aspects about it, specifically, the details about escaped characters will make it a bit more involved, and I'm both a bit busy with other work right now, and not depending on these fixes currently.

So, it's on my backlog, but I don't have a sense of when I will get around to the problem.

@ghost ghost removed the needs-author-feedback This issue / or pull request requires author feedback before more action can be taken. label Jan 28, 2021
@bgianfo bgianfo added the needs-author-feedback This issue / or pull request requires author feedback before more action can be taken. label Feb 1, 2021
@ghost
Copy link

ghost commented Feb 8, 2021

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days.

@bgianfo bgianfo changed the title Fixes to the tracebld sample to better handle very large arguments. Fix: Improve handling of very large arguments in the tracebld sample Mar 5, 2021
@ghost
Copy link

ghost commented Mar 12, 2021

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-author-feedback This issue / or pull request requires author feedback before more action can be taken. status-no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants