ndr: Parenthesize expressions to be cast
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Tue, 4 May 2021 02:09:44 +0000 (14:09 +1200)
committerJoseph Sutton <jsutton@samba.org>
Sun, 1 Oct 2023 22:45:38 +0000 (22:45 +0000)
We must parenthesize each expression that is to be cast to a specific
type, otherwise the cast will apply to only part of the full expression.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=9914

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm

index 1ec037628a728d3b04f17bfdc5ba378e65a041c1..d5506d8c21d637f5cf40a0ab106c892596b985e3 100644 (file)
@@ -371,7 +371,7 @@ sub ParseArrayPullGetSize($$$$$$)
                } else {
                        $self->pidl("if ($array_size < $low || $array_size > $high) {");
                }
-               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value (%\"PRIu32\") out of range (%\"PRIu32\" - %\"PRIu32\")\", $array_size, (uint32_t)$low, (uint32_t)$high);");
+               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value (%\"PRIu32\") out of range (%\"PRIu32\" - %\"PRIu32\")\", $array_size, (uint32_t)($low), (uint32_t)($high));");
 
                $self->pidl("}");
        }
@@ -411,7 +411,7 @@ sub ParseArrayPullGetLength($$$$$$;$)
                } else {
                        $self->pidl("if ($array_length < $low || $array_length > $high) {");
                }
-               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value (%\"PRIu32\") out of range (%\"PRIu32\" - %\"PRIu32\")\", $array_length, (uint32_t)$low, (uint32_t)$high);");
+               $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value (%\"PRIu32\") out of range (%\"PRIu32\" - %\"PRIu32\")\", $array_length, (uint32_t)($low), (uint32_t)($high));");
                $self->pidl("}");
        }
 
@@ -1050,7 +1050,7 @@ sub ParseDataPull($$$$$$$)
                                }
                        }
 
-                       $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value (%$fmt) out of range (%$fmt - %$fmt)\", ($data_type)$var_name, ($data_type)$low, ($data_type)$high);");
+                       $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value (%$fmt) out of range (%$fmt - %$fmt)\", ($data_type)($var_name), ($data_type)($low), ($data_type)($high));");
                        $self->pidl("}");
                }
        } else {