ndrdump: correctly find the public strict by number
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 14 Nov 2019 00:14:08 +0000 (13:14 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Sun, 17 Nov 2019 22:28:41 +0000 (22:28 +0000)
We were finding a function that happened to have the same ordinal
number.

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

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
librpc/tools/ndrdump.c

index 4173f03098d8c15ef32912521a1c1e1e63a25f76..4f812eeda7a97a7fa90e89e7f6df03c03dcb2945 100644 (file)
@@ -66,6 +66,7 @@ static const struct ndr_interface_call *find_struct(
        struct ndr_interface_call *out_buffer)
 {
        unsigned int i;
+       const struct ndr_interface_public_struct *public_struct = NULL;
        if (isdigit(struct_name[0])) {
                char *eptr = NULL;
                i = strtoul(struct_name, &eptr, 0);
@@ -76,23 +77,25 @@ static const struct ndr_interface_call *find_struct(
                               struct_name);
                        exit(1);
                }
-               return &p->calls[i];
-       }
-       for (i=0;i<p->num_public_structs;i++) {
-               if (strcmp(p->public_structs[i].name, struct_name) == 0) {
-                       break;
+               public_struct = &p->public_structs[i];
+       } else {
+               for (i=0;i<p->num_public_structs;i++) {
+                       if (strcmp(p->public_structs[i].name, struct_name) == 0) {
+                               break;
+                       }
                }
-       }
-       if (i == p->num_public_structs) {
-               printf("Public structure '%s' not found\n", struct_name);
-               exit(1);
+               if (i == p->num_public_structs) {
+                       printf("Public structure '%s' not found\n", struct_name);
+                       exit(1);
+               }
+               public_struct = &p->public_structs[i];
        }
        *out_buffer = (struct ndr_interface_call) {
-               .name = p->public_structs[i].name,
-               .struct_size = p->public_structs[i].struct_size,
-               .ndr_pull = p->public_structs[i].ndr_pull,
-               .ndr_push = p->public_structs[i].ndr_push,
-               .ndr_print = p->public_structs[i].ndr_print
+               .name = public_struct->name,
+               .struct_size = public_struct->struct_size,
+               .ndr_pull = public_struct->ndr_pull,
+               .ndr_push = public_struct->ndr_push,
+               .ndr_print = public_struct->ndr_print
        };
        return out_buffer;
 }