pidl-wireshark: if the structure has the flag no_align then set also no_align in...
authorMatthieu Patou <mat@matws.net>
Fri, 11 Oct 2013 20:18:37 +0000 (13:18 -0700)
committerStefan Metzmacher <metze@samba.org>
Thu, 23 Oct 2014 21:12:05 +0000 (23:12 +0200)
Some dissection function will try to do alignment if the no_align flag
is not set.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Matthieu Patou <mat@matws.net>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
pidl/lib/Parse/Pidl/Wireshark/NDR.pm

index 321104fdc3dca4ad49b0c58cc2bed6f6a0ae0e44..6bc03ccd9b96abb478ce8a741059e618180ac0d2 100644 (file)
@@ -647,6 +647,13 @@ sub Struct($$$$)
                $res.="\t".$self->Element($_, $name, $ifname, $switch_info)."\n\n";
        }
 
+       my $doalign = undef;
+       if ($e->{ALIGN} > 1 and not property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
+               $doalign = 1;
+       } elsif (property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
+               $doalign = 0;
+       }
+
        $self->pidl_hdr("int $dissectorname(tvbuff_t *tvb _U_, int offset _U_, packet_info *pinfo _U_, proto_tree *parent_tree _U_, guint8 *drep _U_, int hf_index _U_, guint32 param _U_);");
 
        $self->pidl_fn_start($dissectorname);
@@ -657,16 +664,24 @@ sub Struct($$$$)
        $self->pidl_code($_) foreach (@$vars);
        $self->pidl_code("proto_item *item = NULL;");
        $self->pidl_code("proto_tree *tree = NULL;");
-       if ($e->{ALIGN} > 1) {
+       if (defined($doalign)) {
                $self->pidl_code("dcerpc_info *di = (dcerpc_info *)pinfo->private_data;");
+               if ($doalign == 0) {
+                       $self->pidl_code("gboolean oldalign = di->no_align;");
+               }
        }
        $self->pidl_code("int old_offset;");
        $self->pidl_code("");
 
-       if ($e->{ALIGN} > 1 and not property_matches($e, "flag", ".*LIBNDR_FLAG_NOALIGN.*")) {
-               $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
+       if (defined($doalign)) {
+               if ($doalign == 1) {
+                       $self->pidl_code("ALIGN_TO_$e->{ALIGN}_BYTES;");
+               }
+               if ($doalign == 0) {
+                       $self->pidl_code("di->no_align = TRUE;");
+               }
+               $self->pidl_code("");
        }
-       $self->pidl_code("");
 
        $self->pidl_code("old_offset = offset;");
        $self->pidl_code("");
@@ -680,7 +695,7 @@ sub Struct($$$$)
        $self->pidl_code("\n$res");
 
        $self->pidl_code("proto_item_set_len(item, offset-old_offset);\n");
-       if ($e->{ALIGN} > 1) {
+       if (defined($doalign) and $doalign == 1) {
                $self->pidl_code("");
                $self->pidl_code("if (di->call_data->flags & DCERPC_IS_NDR64) {");
                $self->indent;
@@ -688,6 +703,10 @@ sub Struct($$$$)
                $self->deindent;
                $self->pidl_code("}");
        }
+       if (defined($doalign) and $doalign == 0) {
+               $self->pidl_code("");
+               $self->pidl_code("di->no_align = oldalign;");
+       }
        $self->pidl_code("");
        $self->pidl_code("return offset;");
        $self->deindent;