[PATCH] packetdrill: Zero out last string byte

17 views
Skip to first unread message

Thadeu Lima de Souza Cascardo

unread,
Jun 28, 2016, 10:44:30 AM6/28/16
to packe...@googlegroups.com, ncar...@google.com
When unescaping a string, the last zero byte from the input string must be
copied to the output string. The space required for that extra byte must also be
allocated.

Signed-off-by: Thadeu Lima de Souza Cascardo <casc...@redhat.com>
---
gtests/net/packetdrill/script.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gtests/net/packetdrill/script.c b/gtests/net/packetdrill/script.c
index f669203..861b5b6 100644
--- a/gtests/net/packetdrill/script.c
+++ b/gtests/net/packetdrill/script.c
@@ -216,7 +216,7 @@ char *flags_to_string(struct flag_name *flags_array, u64 flags)
static int unescape_cstring_expression(const char *input_string,
struct expression *out, char **error)
{
- int bytes = strlen(input_string);
+ int bytes = strlen(input_string) + 1;
out->type = EXPR_STRING;
out->value.string = (char *)malloc(bytes);
const char *c_in = input_string;
@@ -255,6 +255,7 @@ static int unescape_cstring_expression(const char *input_string,
++c_in;
++c_out;
}
+ *c_out = *c_in;
return STATUS_OK;
}

--
2.7.4

Michael Tüxen

unread,
Jun 29, 2016, 2:16:09 AM6/29/16
to Thadeu Lima de Souza Cascardo, packe...@googlegroups.com, Neal Cardwell
> On 28 Jun 2016, at 16:44, Thadeu Lima de Souza Cascardo <casc...@redhat.com> wrote:
>
> When unescaping a string, the last zero byte from the input string must be
> copied to the output string. The space required for that extra byte must also be
> allocated.
Hi Thadeu,

I committed your patch in my fork:
https://github.com/nplab/packetdrill/commit/f8da1dfaabff3522c5547d774f9befe2017d5e60
Thanks for reporting the issue and providing a patch.

Best regards
Michael
>
> Signed-off-by: Thadeu Lima de Souza Cascardo <casc...@redhat.com>
> ---
> gtests/net/packetdrill/script.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/gtests/net/packetdrill/script.c b/gtests/net/packetdrill/script.c
> index f669203..861b5b6 100644
> --- a/gtests/net/packetdrill/script.c
> +++ b/gtests/net/packetdrill/script.c
> @@ -216,7 +216,7 @@ char *flags_to_string(struct flag_name *flags_array, u64 flags)
> static int unescape_cstring_expression(const char *input_string,
> struct expression *out, char **error)
> {
> - int bytes = strlen(input_string);
> + int bytes = strlen(input_string) + 1;
> out->type = EXPR_STRING;
> out->value.string = (char *)malloc(bytes);
> const char *c_in = input_string;
> @@ -255,6 +255,7 @@ static int unescape_cstring_expression(const char *input_string,
> ++c_in;
> ++c_out;
> }
> + *c_out = *c_in;
> return STATUS_OK;
> }
>
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups "packetdrill" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to packetdrill...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Neal Cardwell

unread,
Jun 29, 2016, 11:02:29 AM6/29/16
to Thadeu Lima de Souza Cascardo, packetdrill
On Tue, Jun 28, 2016 at 10:44 AM, Thadeu Lima de Souza Cascardo
<casc...@redhat.com> wrote:
> When unescaping a string, the last zero byte from the input string must be
> copied to the output string. The space required for that extra byte must also be
> allocated.
>
> Signed-off-by: Thadeu Lima de Souza Cascardo <casc...@redhat.com>

Thank you so much for the report and fix! I have merged an equivalent fix into
the original Google packetdrill repo on Github at:

https://github.com/google/packetdrill

The commit is:

https://github.com/google/packetdrill/commit/34816ae439b925f424becf47fbcb6f7843877567

And thanks, Michael, for picking this up as well.

Thanks!
neal
Reply all
Reply to author
Forward
0 new messages