From 3437220fe30c481362a6b300903fcfae03849521 Mon Sep 17 00:00:00 2001 From: Seth Hall Date: Tue, 9 Aug 2011 09:51:03 -0400 Subject: [PATCH] piped_exec can now write nulls in the "to_write" argument. - Additional test for testing writing null values. --- src/bro.bif | 9 ++++++++- testing/btest/Baseline/bifs.piped_exec/test.txt | Bin 0 -> 9 bytes testing/btest/bifs/piped_exec.bro | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 testing/btest/Baseline/bifs.piped_exec/test.txt diff --git a/src/bro.bif b/src/bro.bif index d3bbd7c072..144d71af92 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -3631,7 +3631,14 @@ function piped_exec%(program: string, to_write: string%): bool return new Val(false, TYPE_BOOL); } - fprintf(f, "%s", to_write->CheckString()); + const u_char* input_data = to_write->Bytes(); + int input_data_len = to_write->Len(); + int bytes_written = fwrite(input_data, 1, input_data_len, f); + if ( bytes_written != input_data_len ) + { + reporter->Error("Failed to write all given data to %s", prog); + return new Val(false, TYPE_BOOL); + } pclose(f); return new Val(true, TYPE_BOOL); diff --git a/testing/btest/Baseline/bifs.piped_exec/test.txt b/testing/btest/Baseline/bifs.piped_exec/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..a23f66ba7ec8a253a4e1a9887baed69b403be783 GIT binary patch literal 9 QcmZQz$Vkn}$!A~y018+F6#xJL literal 0 HcmV?d00001 diff --git a/testing/btest/bifs/piped_exec.bro b/testing/btest/bifs/piped_exec.bro index 4405f0b500..32fd5c5f80 100644 --- a/testing/btest/bifs/piped_exec.bro +++ b/testing/btest/bifs/piped_exec.bro @@ -1,6 +1,12 @@ # @TEST-EXEC: bro %INPUT >output # @TEST-EXEC: btest-diff output +# @TEST-EXEC: btest-diff test.txt + global cmds = "print \"hello world\";"; cmds = string_cat(cmds, "\nprint \"foobar\";"); piped_exec("bro", cmds); + +# Test null output. +piped_exec("cat > test.txt", "\x00\x00hello\x00\x00"); +