summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2020-12-17 19:16:13 +0100
committerStefan Metzmacher <metze@samba.org>2021-11-02 20:36:16 +0000
commit7a1128cb9a91234ea3e608f02698690673994108 (patch)
treeae28dee87d1762ddc13d4ba3c18164da9bcfe838
parent48f3f52c1be444db33c368d1e674fb829d8af9fc (diff)
downloadsamba-7a1128cb9a91234ea3e608f02698690673994108.tar.gz
lib:ldb-samba: Improve calculate_popt_array_length()
Note that memcmp() doesn't work well with padding bytes. So avoid it! (gdb) ptype/o struct poptOption /* offset | size */ type = struct poptOption { /* 0 | 8 */ const char *longName; /* 8 | 1 */ char shortName; /* XXX 3-byte hole */ /* 12 | 4 */ unsigned int argInfo; /* 16 | 8 */ void *arg; /* 24 | 4 */ int val; /* XXX 4-byte hole */ /* 32 | 8 */ const char *descrip; /* 40 | 8 */ const char *argDescrip; /* total size (bytes): 48 */ Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> (cherry picked from commit c2c7c1f50a8acb3169e19ba4329aa78839b66def)
-rw-r--r--lib/ldb-samba/samba_extensions.c27
-rw-r--r--lib/ldb/tools/cmdline.c2
2 files changed, 23 insertions, 6 deletions
diff --git a/lib/ldb-samba/samba_extensions.c b/lib/ldb-samba/samba_extensions.c
index 65a4079ec97..60aa1a332b5 100644
--- a/lib/ldb-samba/samba_extensions.c
+++ b/lib/ldb-samba/samba_extensions.c
@@ -34,15 +34,32 @@
#include "popt.h"
+static bool is_popt_table_end(const struct poptOption *o)
+{
+ if (o->longName == NULL &&
+ o->shortName =='\0' &&
+ o->arg == NULL) {
+ return true;
+ }
+
+ return false;
+}
/*
work out the length of a popt array
*/
-static unsigned calculate_popt_array_length(struct poptOption *opts)
+static size_t calculate_popt_array_length(struct poptOption *opts)
{
- unsigned i;
- struct poptOption zero_opt = { 0 };
- for (i=0; memcmp(&zero_opt, &opts[i], sizeof(zero_opt)) != 0; i++) ;
+ size_t i = 0;
+
+ for (i = 0; i < UINT32_MAX; i++) {
+ struct poptOption *o = &(opts[i]);
+
+ if (is_popt_table_end(o)) {
+ break;
+ }
+ }
+
return i;
}
@@ -61,7 +78,7 @@ static int extensions_hook(struct ldb_context *ldb, enum ldb_module_hook_type t)
{
switch (t) {
case LDB_MODULE_HOOK_CMDLINE_OPTIONS: {
- unsigned len1, len2;
+ size_t len1, len2;
struct poptOption **popt_options = ldb_module_popt_options(ldb);
struct poptOption *new_array;
diff --git a/lib/ldb/tools/cmdline.c b/lib/ldb/tools/cmdline.c
index affce47ac84..ff25fe05ec7 100644
--- a/lib/ldb/tools/cmdline.c
+++ b/lib/ldb/tools/cmdline.c
@@ -259,7 +259,7 @@ static struct poptOption builtin_popt_options[] = {
.descrip = "show extended DNs",
.argDescrip = NULL
},
- {0}
+ POPT_TABLEEND
};
void ldb_cmdline_help(struct ldb_context *ldb, const char *cmdname, FILE *f)