1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00
samba-mirror/source3/param/test_lp_load.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

121 lines
2.7 KiB
C
Raw Normal View History

/*
* Unix SMB/CIFS implementation.
* Test for lp_load()
* Copyright (C) Michael Adam 2008
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "lib/cmdline/cmdline.h"
#include "lib/param/param.h"
int main(int argc, const char **argv)
{
const char *config_file = NULL;
int ret = 0;
poptContext pc;
char *count_str = NULL;
int i, count = 1;
int opt;
bool ok;
struct poptOption long_options[] = {
POPT_AUTOHELP
{
.longName = "count",
.shortName = 'c',
.argInfo = POPT_ARG_STRING,
.arg = &count_str,
.val = 1,
.descrip = "Load config <count> number of times"
},
POPT_COMMON_DEBUG_ONLY
POPT_COMMON_VERSION
POPT_TABLEEND
};
TALLOC_CTX *frame = talloc_stackframe();
struct loadparm_context *lp_ctx = NULL;
smb_init_locale();
ok = samba_cmdline_init(frame,
SAMBA_CMDLINE_CONFIG_NONE,
false /* require_smbconf */);
if (!ok) {
DBG_ERR("Failed to init cmdline parser!\n");
TALLOC_FREE(frame);
exit(ENOMEM);
}
lp_ctx = samba_cmdline_get_lp_ctx();
lpcfg_set_cmdline(lp_ctx, "log level", "0");
pc = samba_popt_get_context(getprogname(),
argc,
argv,
long_options,
0);
if (pc == NULL) {
DBG_ERR("Failed to setup popt context!\n");
TALLOC_FREE(frame);
exit(1);
}
poptSetOtherOptionHelp(pc, "[OPTION...] <config-file>");
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case POPT_ERROR_BADOPT:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
poptPrintUsage(pc, stderr, 0);
exit(1);
}
}
if (poptPeekArg(pc)) {
s3/param: Fix use after free with popt-1.19 popt1.19 fixes a leak that exposes a use as free, make sure we duplicate return of poptGetArg if poptFreeContext is called before we use it. ==5325== Invalid read of size 1 ==5325== at 0x4849782: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859E1C: talloc_strdup (talloc.c:2470) ==5325== by 0x48C0D37: talloc_sub_basic (substitute.c:303) ==5325== by 0x4894B98: lp_load_ex (loadparm.c:4004) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8b0 is 0 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 1 ==5325== at 0x4849794: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859E1C: talloc_strdup (talloc.c:2470) ==5325== by 0x48C0D37: talloc_sub_basic (substitute.c:303) ==5325== by 0x4894B98: lp_load_ex (loadparm.c:4004) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8b1 is 1 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 8 ==5325== at 0x484D3AE: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859DC2: __talloc_strlendup (talloc.c:2457) ==5325== by 0x4859E32: talloc_strdup (talloc.c:2470) ==5325== by 0x48C0D37: talloc_sub_basic (substitute.c:303) ==5325== by 0x4894B98: lp_load_ex (loadparm.c:4004) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8b0 is 0 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 2 ==5325== at 0x484D400: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859DC2: __talloc_strlendup (talloc.c:2457) ==5325== by 0x4859E32: talloc_strdup (talloc.c:2470) ==5325== by 0x48C0D37: talloc_sub_basic (substitute.c:303) ==5325== by 0x4894B98: lp_load_ex (loadparm.c:4004) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8c0 is 16 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 1 ==5325== at 0x484D430: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859DC2: __talloc_strlendup (talloc.c:2457) ==5325== by 0x4859E32: talloc_strdup (talloc.c:2470) ==5325== by 0x48C0D37: talloc_sub_basic (substitute.c:303) ==5325== by 0x4894B98: lp_load_ex (loadparm.c:4004) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8c2 is 18 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 1 ==5325== at 0x4849782: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859E1C: talloc_strdup (talloc.c:2470) ==5325== by 0x4B3B74B: add_to_file_list (loadparm.c:1023) ==5325== by 0x4894BD4: lp_load_ex (loadparm.c:4011) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8b0 is 0 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 1 ==5325== at 0x4849794: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859E1C: talloc_strdup (talloc.c:2470) ==5325== by 0x4B3B74B: add_to_file_list (loadparm.c:1023) ==5325== by 0x4894BD4: lp_load_ex (loadparm.c:4011) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8b1 is 1 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 8 ==5325== at 0x484D3AE: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859DC2: __talloc_strlendup (talloc.c:2457) ==5325== by 0x4859E32: talloc_strdup (talloc.c:2470) ==5325== by 0x4B3B74B: add_to_file_list (loadparm.c:1023) ==5325== by 0x4894BD4: lp_load_ex (loadparm.c:4011) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8b0 is 0 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 2 ==5325== at 0x484D400: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859DC2: __talloc_strlendup (talloc.c:2457) ==5325== by 0x4859E32: talloc_strdup (talloc.c:2470) ==5325== by 0x4B3B74B: add_to_file_list (loadparm.c:1023) ==5325== by 0x4894BD4: lp_load_ex (loadparm.c:4011) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8c0 is 16 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== ==5325== Invalid read of size 1 ==5325== at 0x484D430: memmove (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4859DC2: __talloc_strlendup (talloc.c:2457) ==5325== by 0x4859E32: talloc_strdup (talloc.c:2470) ==5325== by 0x4B3B74B: add_to_file_list (loadparm.c:1023) ==5325== by 0x4894BD4: lp_load_ex (loadparm.c:4011) ==5325== by 0x489529E: lp_load_with_registry_shares (loadparm.c:4237) ==5325== by 0x10ABD7: main (test_lp_load.c:98) ==5325== Address 0x72da8c2 is 18 bytes inside a block of size 20 free'd ==5325== at 0x484617B: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B8F8B8: poptResetContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x4B905D4: poptFreeContext (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB8E: main (test_lp_load.c:90) ==5325== Block was alloc'd at ==5325== at 0x48437B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==5325== by 0x4B912EE: poptGetNextOpt (in /usr/lib64/libpopt.so.0.0.2) ==5325== by 0x10AB49: main (test_lp_load.c:74) ==5325== BUG: https://bugzilla.samba.org/show_bug.cgi?id=15205 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Ralph Boehme <slow@samba.org>
2022-10-14 13:23:37 +03:00
config_file = talloc_strdup(frame, poptGetArg(pc));
if (config_file == NULL) {
DBG_ERR("out of memory\n");
TALLOC_FREE(frame);
exit(1);
}
} else {
config_file = get_dyn_CONFIGFILE();
}
poptFreeContext(pc);
if (count_str != NULL) {
count = atoi(count_str);
}
for (i=0; i < count; i++) {
printf("call lp_load() #%d: ", i+1);
if (!lp_load_with_registry_shares(config_file)) {
printf("ERROR.\n");
ret = 1;
goto done;
}
printf("ok.\n");
}
done:
gfree_loadparm();
TALLOC_FREE(frame);
return ret;
}