[PATCH] base/utils.c: Remove code handling escape characters

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[PATCH] base/utils.c: Remove code handling escape characters

Post by Guest »

This is a multi-part message in MIME format.
--------------090109050305080003000907
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

Hi Andreas,

On 08/01/13 10:12, Andreas Ericsson wrote:
> lib/runcmd.c is the library code which shouldn't change its behaviour. The
> code in utils.c should be removed instead.

The attached patch removes the general escape handling code from
utils.c, with the exception of "\!" as otherwise it wouldn't be possible
to include a "!" inside an argument.

If you think this should be done differently then let me know and I'll
amend the patch.

> On the other hand, the runcmd.c code should have a flag argument one can
> use to tell it to ignore certain characters, with "ignore everything" to
> be taken as "split on every whitespace-sequence and disregard quoting and
> escaping entirely".

What's the use case for this?

Cheers,

Adam
--
Open Source Consultant, Transitiv Technologies Ltd.

Business Critical Support and Services for Open Source Software.

T: 0203 384 7207
E: adam.james@transitiv.co.uk
W: http://www.transitiv.co.uk

--------------090109050305080003000907
Content-Type: text/x-patch;
name="0001-base-utils.c-Remove-code-handling-escape-characters.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0001-base-utils.c-Remove-code-handling-escape-characters.pat";
filename*1="ch"

From e2e6b6951a1c354e8eee341125dd648fbf2a2092 Mon Sep 17 00:00:00 2001
From: Adam James
Date: Thu, 10 Jan 2013 15:56:52 +0000
Subject: [PATCH] base/utils.c: Remove code handling escape characters

This patches moves the responsibility for handling escape characters
from the core to worker processes. The exclamation mark is excepted as
it is used as the argument delimiter. Note that any code using the
runcmd functions from libnagios get escape handling for free.
---
base/utils.c | 20 +++++++-------------
1 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/base/utils.c b/base/utils.c
index 1c12e9b..e8a77bf 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -571,7 +571,6 @@ int get_raw_command_line_r(nagios_macros *mac, command *cmd_ptr, char *cmd, char
register int x = 0;
register int y = 0;
register int arg_index = 0;
- register int escaped = FALSE;

log_debug_info(DEBUGL_FUNCTIONS, 0, "get_raw_command_line_r()\n");

@@ -608,22 +607,17 @@ int get_raw_command_line_r(nagios_macros *mac, command *cmd_ptr, char *cmd, char
/* can't use strtok(), as that's used in process_macros... */
for(arg_index++, y = 0; y < sizeof(temp_arg) - 1; arg_index++) {

- /* backslashes escape */
- if(cmd[arg_index] == '\\' && escaped == FALSE) {
- escaped = TRUE;
- continue;
- }
-
- /* end of argument */
- if((cmd[arg_index] == '!' && escaped == FALSE) || cmd[arg_index] == '\x0')
+ /* handle escaped argument delimiters */
+ if(cmd[arg_index] == '\\' && cmd[arg_index+1] == '!') {
+ arg_index++;
+ } else if(cmd[arg_index] == '!' || cmd[arg_index] == '\x0') {
+ /* end of argument */
break;
+ }

- /* normal of escaped char */
+ /* copy the character */
temp_arg[y] = cmd[arg_index];
y++;
-
- /* clear escaped flag */
- escaped = FALSE;
}
temp_arg[y] = '\x0';

--
1.7.1


--------------090109050305080003000907--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: adam.james@transitiv.co.uk
Locked