summaryrefslogtreecommitdiff
path: root/lib/util/tests
AgeCommit message (Collapse)AuthorFilesLines
2026-03-25util/tests: Test that talloc_keep_secret() does not overwrite the namePavel Filipenský1-0/+20
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
2026-03-25util/tests: Extend the 'test_talloc_keep_secret' testPavel Filipenský1-0/+7
Test that talloc_strdup() puts the secret as talloc name. Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
2026-03-25Revert "lib/util: Avoid overwriting talloc chunk name in talloc_keep_secret()"Pavel Filipenský1-0/+4
This reverts commit 7e693b55730ceba2ef326286a0c68d5d91324a22. Without this commit, for memory allocated via e.g. talloc_strdup(), talloc name would reveal memory content. Signed-off-by: Pavel Filipenský <pfilipensky@samba.org>
2026-03-01torture: Use SINGLETON_CACHE_TALLOC in testsVolker Lendecke1-12/+12
GETWD_CACHE is on its way out. Despite not having _TALLOC in its name nor it being marked as talloc in memcache.h, memcache_is_talloc() shows it as being talloc'ed. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2026-01-28lib:util:debug tests for JSON logging macrosGary Lockyer1-0/+285
Add unit tests for the new JSON debugging macros DBGJSON and DBGJSONC BUG: https://bugzilla.samba.org/show_bug.cgi?id=15898 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Volker Lendecke <vl@samba.org>
2025-12-08lib/util: Add tests for the new secure data_blob_..._s() functionsPavel Filipenský1-1/+56
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2025-12-08lib/util: Fix trailing white spaces in tests/data_blob.cPavel Filipenský1-6/+6
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2025-12-08lib/util: Avoid overwriting talloc chunk name in talloc_keep_secret()Pavel Filipenský1-4/+0
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2025-11-11Replace memset_s() with memset_explicit()Andreas Schneider1-11/+8
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-10-17Add missing include needed for cmocka.hAndreas Schneider1-0/+1
This will be required in future. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2025-09-28lib/util: Fix CID 1414760 - Resource leakShweta Sodani1-1/+5
If read is failed torture_assert could return without freeing the t. Fixing the leak. Signed-off-by: Shweta Sodani <ssodani@redhat.com> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Vinit Agnihotri <vagnihot@redhat.com> Reviewed-by: Anoop C S <anoopcs@samba.org> Autobuild-User(master): Anoop C S <anoopcs@samba.org> Autobuild-Date(master): Sun Sep 28 09:30:56 UTC 2025 on atb-devel-224
2025-08-12lib/util: Fix CID 1414760 - Memory leakShweta Sodani1-3/+7
local variable 't' is reusing in child process, resulting the leaking the tfork object as a side effect. This fixes coverity issue#1414760 Signed-off-by: Shweta Sodani <ssodani@redhat.com> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Vinit Agnihotri <vagnihot@redhat.com> Reviewed-by: Shachar Sharon <ssharon@redhat.com> Autobuild-User(master): Anoop C S <anoopcs@samba.org> Autobuild-Date(master): Tue Aug 12 09:32:19 UTC 2025 on atb-devel-224
2024-04-16lib: Give lib/util/util_file.c its own header fileVolker Lendecke1-0/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
2024-04-10util:test: test_ms_fn_match_protocol_no_wildcard: allow -1Douglas Bagnall1-1/+1
We have changed strcasecmp_m() to return -1 in a place where it used to return -3. This upset a test, but it shouldn't have: the exact value of the negative int is not guaranteed by the function. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-10util:binsearch: user NUMERIC_CMP()Douglas Bagnall1-2/+4
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-04-14lib:util: Fix code spellingAndreas Schneider2-2/+2
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-01-10lib: Remove idtree from samba_util.hVolker Lendecke1-0/+1
No need to recompile the world when only a few files need this. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2022-12-01util: add stable sort functionsDouglas Bagnall1-0/+317
Sometimes (e.g. in lzxpress Huffman encoding, and in some of our tests: c.f. https://lists.samba.org/archive/samba-technical/2018-March/126010.html) we want a stable sort algorithm (meaning one that retains the previous order of items that compare equal). The GNU libc qsort() is *usually* stable, in that it first tries to use a mergesort but reverts to quicksort if the necessary allocations fail. That has led Samba developers to unthinkingly assume qsort() is stable which is not the case on many platforms, and might not always be on GNU/Linuxes either. This adds four functions. stable_sort() sorts an array, and requires an auxiliary working array of the same size. stable_sort_talloc() takes a talloc context so it ca create a working array and call stable_sort(). stable_sort_r() takes an opaque context blob that gets passed to the compare function, like qsort_r() and ldb_qsort(). And stable_sort_talloc_r() rounds out the quadrant. These are LGPL so that the can be used in ldb, which has problems with unstable sort. The tests are borrowed and extended from test_ldb_qsort.c. When sorting non-trivial structs this is roughly as fast as GNU qsort, but GNU qsort has optimisations for small items, using direct assignments of rather than memcpy where the size allows the item to be cast as some kind of int. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-06-17util/debug: share classname table with testsDouglas Bagnall1-63/+7
The executables generated from lib/util/tests/test_logging.c are used by the samba.tests.logfiles tests to test logging with various smb.confs that assign classes to various files at different levels etc. Previously test_logging.c had its own version of the table; now it shares one with debug.c We put the table in a sub-directory (lib/util/debug-classes/), because adding local_include=True to the wscript_build stanza causes the compiler confusion between <time.h> and lib/util/time.h. Note: there are still two other lists of the class names, in python/samba/tests/logfiles.py and docs-xml/smbdotconf/logging/loglevel.xml. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17tests: rename logging test sourceDouglas Bagnall1-0/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17tests: adapt logging test for s3.Douglas Bagnall1-3/+8
There is one knownfail, where it seems an smb.conf like log file = foo log level = 2 tdb:2@baa ldb:3 will send the ldb logs to 'baa' instead of 'foo' (i.e., the last opened log file, rather than the default log file). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17tests: test source4 cmdline/smb.conf log levelDouglas Bagnall1-0/+197
The 'log level' line in smb.conf allows messages from different log classes to be sent to different places, but we have not tested that this works. Now we do, somewhat. The test involves running a special binary based on a stripped down source4/samba/server.c that just starts up, parses the command line and a given smb.conf, then logs messages from multiple classes and exits. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Add test of mem_equal_const_time()Joseph Sutton1-0/+22
Ensure that it gives the correct results for comparing two memory regions. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Add test of data_blob_equal_const_time()Joseph Sutton1-0/+47
Ensure that it gives the correct results for comparing two data blobs. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-05-02lib/util: add tests for data_blob_append() with the resulting blob length=0Stefan Metzmacher1-0/+26
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15050 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: add a test for null_nttime(NTTIME_THAW)Ralph Boehme1-0/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: update null_nttime() of -1: -1 is NTTIME_FREEZERalph Boehme1-1/+1
NTTIME_FREEZE is not a nil sentinel value, instead it implies special, yet unimplemented semantics. Callers must deal with those values specifically and null_nttime() must not lie about their nature. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: use NTTIME_FREEZE in a null_nttime() testRalph Boehme1-1/+1
No change in behaviour. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: fix null_nttime() testsRalph Boehme1-1/+1
The test was checking -1 twice: torture_assert(tctx, null_nttime(-1), "-1"); torture_assert(tctx, null_nttime(-1), "-1"); The first line was likely supposed to test the value "0". BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-08lib: add sys_block_align[_truncate]()Ralph Boehme1-0/+68
This implements MS-FSA algorithms BlockAlign() and BlockAlignTruncate(). Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-06-30lib: add sys_io_ranges_overlap()Ralph Boehme1-0/+110
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12033 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-06-18torture: talloc_string_sub tests for utf-8 brevityDouglas Bagnall1-0/+58
If we allow overly long UTF-8 sequences (in the tests, encoding '\0' as 2, 3, or 4 bytes), it might be possible for bad strings to slip through. We fail. But wait for the next commit. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14684 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-05-11lib: Add str_list_add_printf()Volker Lendecke1-2/+27
Build up execv argument lists Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-04-16lib/util: fix timespec normalizationPhilipp Gesang1-0/+53
When fixing up timespec structs, negative values for the ns part should be taken into account. Also, the range for a valid ns part is [0, 1000000000), not [0, 1000000000]. Signed-off-by: Philipp Gesang <philipp.gesang@intra2net.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-03-10lib/util: Replace buggy string_sub_talloc() with talloc_string_sub() in lib/utilAndrew Bartlett1-7/+7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14658 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Wed Mar 10 08:06:25 UTC 2021 on sn-devel-184
2021-03-09lib: Align integer typesVolker Lendecke1-2/+3
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-02-03lib:util: Add cache oversize test for memcacheAndreas Schneider1-0/+39
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14625 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2021-02-03lib:util: Add basic memcache unit testAndreas Schneider1-0/+122
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14625 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2021-01-06lib:util: Add directory_create_or_exists_recursive()Andreas Schneider1-5/+111
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14601 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-11-13s4-torture: test file_line_parse as wellGünther Deschner1-0/+31
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Fri Nov 13 17:47:33 UTC 2020 on sn-devel-184
2020-08-24lib/util: Move cleanup for unit test in teardown functionChristof Schmitt1-3/+9
Where to call rmdir does not matter, but that should avoid the TOCTOU warning from CID 1466194 and might be slightly cleaner. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Mon Aug 24 03:10:09 UTC 2020 on sn-devel-184
2020-08-24lib/util: Remove wrong return statement in unit testChristof Schmitt1-2/+0
Fixes CID 1466195 Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-08-24lib/util: Fix cleanup in unit testChristof Schmitt1-1/+1
Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-08-16util: Add cmocka unit test for directory_create_or_existsChristof Schmitt1-0/+234
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14166 Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Sun Aug 16 07:06:59 UTC 2020 on sn-devel-184
2020-08-03lib: relicense smb_strtoul(l) under LGPLv3Ralph Boehme1-0/+1
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Aug 3 22:21:04 UTC 2020 on sn-devel-184
2020-06-29util: fix build on AIX by fixing the order of replace.h includeBjoern Jacke1-1/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14422 Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Björn Jacke <bjacke@samba.org> Autobuild-Date(master): Mon Jun 29 18:19:04 UTC 2020 on sn-devel-184
2020-05-15lib:util: Add test for path_expand_tilde()Andreas Schneider1-0/+127
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14370 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-05-04CVE-2020-10704: lib util asn1: Add ASN.1 max tree depthGary Lockyer1-1/+1
Add maximum parse tree depth to the call to asn1_init, which will be used to limit the depth of the ASN.1 parse tree. Credit to OSS-Fuzz REF: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20454 BUG: https://bugzilla.samba.org/show_bug.cgi?id=14334 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-02-21lib:util: Add test to verify old and new macros are the sameAndreas Schneider1-0/+273
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-02-21lib:util: Add bytearray.hAndreas Schneider1-0/+435
This is an implementation which doesn't have undefined behavior problems. It casts correctly that calculations are don in the correct integer space. Also the naming is less confusing than what we have in byteorder.h. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>