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

use dynamic sized command line buffer #431

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

sni
Copy link
Contributor

@sni sni commented Jun 28, 2023

Previously we used a fixed size 8k buffer when parsing command line arguments. This sounds much, but there are command lines bigger than 8k and they are simply cut off without any warning.

Instead we use a dynamic sized buffer with the size of the raw command now.

(while on it, fixing the crazy indent)

Previously we used a fixed size 8k buffer when parsing command line arguments.
This sounds much, but there are command lines bigger than 8k and they are
simply cut off without any warning.

Instead we use a dynamic sized buffer with the size of the raw command now.
/* get the command arguments */
if (cmd != NULL) {
if (cmd == NULL) {
log_debug_info(DEBUGL_COMMANDS | DEBUGL_CHECKS | DEBUGL_MACROS, 2, "Expanded Command Output: %s\n", *full_command);
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, it means that there was no need to further expand the command? I.e for commands like DISABLE_NOTIFICATIONS where there are no args

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, this is not external commands, but check commands... Similar point though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tbh, i didn't check where this is used, i just inverted the huge if clause to return early instead of having the hole function in a huge if. The functionality did not change at this point.
I should have put this in a separate commit.

Copy link
Contributor

@jacobbaungard jacobbaungard left a comment

Choose a reason for hiding this comment

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

My C is probably already rusty, but don't we just put a single, un-expanded check argument into the temp_arg variable?

I.e if we have example_command!$_MY_MACRO$ we end up putting $_MY_MACRO$ into temp_arg and passing it to process_macros_r which puts the expanded version of the macro in arg_buffer ?

@sni
Copy link
Contributor Author

sni commented Jul 6, 2023

that's right, but in my case i had command with very long arguments like example_command!some very long arg!other arg and it was cut off, if the argument was more than 8k.

@jacobbaungard
Copy link
Contributor

You had a single argument that was above 8k bytes!?

@sni
Copy link
Contributor Author

sni commented Jul 6, 2023

right, basically a tarball of a folder as base64 encoded string :-) I know, not the usual usecase, but naemon should either work or throw an error :-)

Copy link
Contributor

@jacobbaungard jacobbaungard left a comment

Choose a reason for hiding this comment

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

Jeez OK! Seems sensible enough. I guess we might even save some bytes on normal smaller commands like this.

When I first read the title I figured it would be the total check_command (expanded/non expanded) that we change, so I guess just make sure to note in the changelog that it's the size of the individual command line args that can now be longer.

@nook24
Copy link
Member

nook24 commented Jul 6, 2023

When I first read the title I figured it would be the total check_command (expanded/non expanded) that we change, so I guess just make sure to note in the changelog that it's the size of the individual command line args that can now be longer.

Honestly, I was also testing the total check command length first^^

@sni sni merged commit b5c28d2 into naemon:master Jul 6, 2023
20 checks passed
@sni
Copy link
Contributor Author

sni commented Jul 6, 2023

sorry for the confusion :-)
i will try to make the changelog entry more clear.

thanks for the review.

@sni sni deleted the improve_command_line_buffer branch February 9, 2024 15:14
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.

None yet

3 participants