[SCM] Samba Shared Repository - branch master updated
Ralph Böhme
slow at samba.org
Sun Jun 30 12:48:02 UTC 2019
The branch, master has been updated
via d5383297f03 tests-util: Adding test to verify "allow no conversion" flag
via dac981a3887 tests-util: Adding test to verify "full-string-conversion" flag
via ed533debc40 tests-util: Adding test to verify "allow-negative" flag
via 1756cea95b8 util: cleanup API change for strtoul(l) wrappers
via 3bc973c6022 source4: Update all consumers of strtoul_err(), strtoull_err() to new API
via a75727f191c source3: Update all consumers of strtoul_err(), strtoull_err() to new API
via bf020a8c8db nsswitch: Update all consumers of strtoul_err(), strtoull_err() to new API
via 39a518b6717 libcli: Update all consumers of strtoul_err(), strtoull_err() to new API
via a8bbd60fd9d lib: Update all consumers of strtoul_err(), strtoull_err() to new API
via 73640b8ad8c ctdb: Update all consumers of strtoul_err(), strtoull_err() to new API
via b1c2f168cef lib: Add capability to enable standard glibc behaviour for string to int conversion
via f0d1339ed5e lib: Add check for full string consumption when converting string to int
via f2997ad677d lib: Prepare for strtoul_err(), strtoull_err() API change
via 7fd0cd02b75 lib: Add flag definitions to control the internal string to int conversion routines
via ba021e3cfb2 tests-util: Adding test to verify "no-conversion" detection
via 9af0614bcb1 tests-util: Adding test to verify negative "number" detection
via c878fbcec9c tests-util: Adding strtoul(l)_err() test leaving errno untouched
via cd66614a4e8 s3: smbd: Make open_directory() always open a fd.
from 98e34c299dd .gitlab-ci.yml: Increase resources for samba-ad-dc-backup job
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit d5383297f0389d01d42479b074f5e81619e03ddb
Author: Swen Schillig <swen at linux.ibm.com>
Date: Mon Jun 3 10:58:11 2019 +0200
tests-util: Adding test to verify "allow no conversion" flag
The internal string conversion routines smb_strtoul(l) return
an error if the provided string could not be converted to an integer.
This can be the case if the string is empty or if it starts with non-numeric
characters which cannot be converted.
The standard C library, however, does allow this and simply returns 0 as the
converted value.
If this behaviour is wanted, it can be enabled by using
the "SMB_STR_ALLOW_NO_CONVERSION" flag.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
Autobuild-User(master): Ralph Böhme <slow at samba.org>
Autobuild-Date(master): Sun Jun 30 12:47:24 UTC 2019 on sn-devel-184
commit dac981a3887fe79650b38e63799e344b22c8f5f1
Author: Swen Schillig <swen at linux.ibm.com>
Date: Mon Jun 3 10:37:07 2019 +0200
tests-util: Adding test to verify "full-string-conversion" flag
The standard string to integer conversion routines stop at the first
character which cannot be converted to a number.
However, if such a character is found, it is not considered an error.
With the flag "SMB_STR_FULL_STR_CONV" enabled, an error will be returned
if the string could not be converted entirely.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit ed533debc40f3173326c65a90ae344d01ec1d427
Author: Swen Schillig <swen at linux.ibm.com>
Date: Mon Jun 3 10:13:52 2019 +0200
tests-util: Adding test to verify "allow-negative" flag
The standard string to integer conversion routines allow strings
with a leading "-" to indicate a negative number.
However, the returned value is always an unsigned value representing
the bit-pattern of this negative value.
Typically, this behaviour is NOT wanted and therefore the standard
behavior of the internal smb_strtoul(l) return an erros in such situations.
It can be enabled though by using the flag SMB_STR_ALLOW_NEGATIVE.
This test verifies the correct processing.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit 1756cea95b844f99ae583860ee022ed56cf09aad
Author: Swen Schillig <swen at linux.ibm.com>
Date: Fri Apr 12 17:28:23 2019 +0200
util: cleanup API change for strtoul(l) wrappers
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit 3bc973c6022ee79f57459849bc5c104795897fde
Author: Swen Schillig <swen at linux.ibm.com>
Date: Tue Jun 4 09:06:37 2019 +0200
source4: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit a75727f191c53ca358cdef930b75d169793f59a3
Author: Swen Schillig <swen at linux.ibm.com>
Date: Tue Jun 4 09:04:15 2019 +0200
source3: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit bf020a8c8db6bb6a0386d3bf69d40116601b1aca
Author: Swen Schillig <swen at linux.ibm.com>
Date: Tue Jun 4 09:01:02 2019 +0200
nsswitch: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit 39a518b6717a4687f43333b3e62a1765d45f5bff
Author: Swen Schillig <swen at linux.ibm.com>
Date: Tue Jun 4 08:59:07 2019 +0200
libcli: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit a8bbd60fd9d10afa0aaf9359782428b8836a9732
Author: Swen Schillig <swen at linux.ibm.com>
Date: Tue Jun 4 08:57:03 2019 +0200
lib: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit 73640b8ad8ced213d4855a2698df0d15318696ac
Author: Swen Schillig <swen at linux.ibm.com>
Date: Fri Apr 12 16:58:13 2019 +0200
ctdb: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit b1c2f168ceff3e425462563fe5f73a655c77b47e
Author: Swen Schillig <swen at linux.ibm.com>
Date: Thu Apr 11 14:46:49 2019 +0200
lib: Add capability to enable standard glibc behaviour for string to int conversion
Adding two addtl. flags SAMBA_STR_ALLOW_NO_CONVERSION and SAMBA_STR_GLIBC_STANDARD
for the wrappers strtoul_err() and strtoull_err() providing the possibility
to get standard glibc behaviour for string to integer conversion.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit f0d1339ed5e417915964bf4612123d67bc10f2f2
Author: Swen Schillig <swen at linux.ibm.com>
Date: Thu Apr 11 14:42:37 2019 +0200
lib: Add check for full string consumption when converting string to int
Some callers want to have the entire string being used for a
string to integer conversion, otherwise flag an error.
This is possible by providing the SAMBA_STR_FULL_STR_CONV flag.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit f2997ad677dbbe96bd2ea73c7632e7e81876f1e8
Author: Swen Schillig <swen at linux.ibm.com>
Date: Thu Apr 11 11:22:02 2019 +0200
lib: Prepare for strtoul_err(), strtoull_err() API change
In order to still be bisectable when changing the API for the wrappers
strtoul_err() and strtoull_err() some preparations need to be performed.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit 7fd0cd02b75782dc6e9a4755d3404e738a92e719
Author: Swen Schillig <swen at linux.ibm.com>
Date: Tue Jun 25 10:25:08 2019 +0200
lib: Add flag definitions to control the internal string to int conversion routines
The following flags are defined intially
SMB_STR_STANDARD # raise error if negative or non-numeric
SMB_STR_ALLOW_NEGATIVE # allow strings with a leading "-"
SMB_STR_FULL_STR_CONV # entire string must be converted
SMB_STR_ALLOW_NO_CONVERSION # allow empty strings or non-numeric
SMB_STR_GLIBC_STANDARD # act exactly as the standard glibc strtoul
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit ba021e3cfb2d8497f0e62001782387547e996ded
Author: Swen Schillig <swen at linux.ibm.com>
Date: Wed Apr 10 10:52:35 2019 +0200
tests-util: Adding test to verify "no-conversion" detection
The standard string to integer conversion routines return zero
if a string was to be converted which did not reflect a number.
It is not flag'ed as an error.
The wrapper functions strtoul_err() and strtoull_err() are expected
to exactly do this.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit 9af0614bcb1750e29a1018e7c6fb6f655cb594fd
Author: Swen Schillig <swen at linux.ibm.com>
Date: Wed Apr 10 10:44:06 2019 +0200
tests-util: Adding test to verify negative "number" detection
Verify that a string representing a negative number is throwing an error.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit c878fbcec9cefbcc1f3a966689cd7375eaf8632f
Author: Swen Schillig <swen at linux.ibm.com>
Date: Wed Apr 10 10:24:52 2019 +0200
tests-util: Adding strtoul(l)_err() test leaving errno untouched
The wrapper functions strtoul_err() and strtoull_err() trigger
other functions/routines which modify errno.
However, callers of those wrapper functions expect errno to be unchanged.
This test verifies the expectation.
Signed-off-by: Swen Schillig <swen at linux.ibm.com>
Reviewed-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Christof Schmitt <cs at samba.org>
commit cd66614a4e8a8f93e1debb8a87dd2afd46b02990
Author: Jeremy Allison <jra at samba.org>
Date: Fri Jun 28 10:20:35 2019 -0700
s3: smbd: Make open_directory() always open a fd.
As we never use kernel oplocks on directory handles,
there is no reason not to always open file descriptors (no
more "stat" opens on directories).
Preparing to have SMB1search use real directory
opens.
Signed-off-by: Jeremy Allison <jra at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
-----------------------------------------------------------------------
Summary of changes:
ctdb/protocol/protocol_util.c | 10 +-
ctdb/server/ctdb_recovery_helper.c | 6 +-
ctdb/tools/ctdb.c | 30 +++-
lib/ldb-samba/ldb_matching_rules.c | 18 +-
lib/ldb-samba/ldif_handlers.c | 2 +-
lib/param/loadparm.c | 4 +-
lib/util/access.c | 9 +-
lib/util/asn1.c | 6 +-
lib/util/tests/util.c | 193 +++++++++++++++++++++
lib/util/util.c | 82 ++++++---
lib/util/util.h | 13 +-
lib/util/util_str.c | 7 +-
libcli/security/dom_sid.c | 6 +-
nsswitch/libwbclient/wbc_idmap.c | 18 +-
nsswitch/libwbclient/wbc_sid.c | 24 ++-
nsswitch/wbinfo.c | 9 +-
source3/groupdb/mapping.c | 5 +-
source3/groupdb/mapping_tdb.c | 21 ++-
source3/lib/interface.c | 17 +-
source3/lib/messages_dgm.c | 4 +-
source3/lib/namemap_cache.c | 10 +-
source3/lib/sysquotas.c | 6 +-
source3/lib/tldap_util.c | 2 +-
source3/lib/util_str.c | 6 +-
source3/modules/vfs_ceph_snapshots.c | 20 +--
source3/modules/vfs_preopen.c | 2 +-
source3/modules/vfs_snapper.c | 2 +-
source3/modules/vfs_unityed_media.c | 7 +-
source3/passdb/account_pol.c | 6 +-
source3/passdb/pdb_ldap.c | 53 ++++--
source3/passdb/pdb_tdb.c | 6 +-
source3/rpcclient/cmd_samr.c | 2 +-
source3/rpcclient/cmd_spoolss.c | 6 +-
source3/smbd/open.c | 34 ++--
source3/utils/net_idmap.c | 5 +-
source3/utils/net_registry.c | 8 +-
source3/utils/net_rpc_registry.c | 2 +-
source3/utils/net_sam.c | 9 +-
source3/utils/pdbedit.c | 9 +-
source3/utils/regedit_dialog.c | 5 +-
source3/winbindd/idmap_ldap.c | 6 +-
source3/winbindd/winbindd_lookuprids.c | 2 +-
source3/winbindd/winbindd_util.c | 20 ++-
source4/dns_server/dlz_bind9.c | 2 +-
source4/dsdb/common/dsdb_dn.c | 2 +-
source4/dsdb/common/util.c | 6 +-
source4/dsdb/samdb/ldb_modules/dirsync.c | 5 +-
.../dsdb/samdb/ldb_modules/partition_metadata.c | 2 +-
source4/dsdb/samdb/ldb_modules/samldb.c | 6 +-
source4/dsdb/samdb/ldb_modules/schema_load.c | 6 +-
source4/dsdb/schema/schema_prefixmap.c | 2 +-
source4/lib/registry/ldb.c | 12 +-
source4/lib/socket/interface.c | 9 +-
source4/libcli/resolve/dns_ex.c | 2 +-
source4/nbt_server/wins/winsdb.c | 5 +-
source4/rpc_server/lsa/dcesrv_lsa.c | 5 +-
source4/torture/nbench/nbench.c | 6 +-
source4/torture/smb2/sharemode.c | 2 +-
58 files changed, 576 insertions(+), 208 deletions(-)
Changeset truncated at 500 lines:
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index f43afbc58d0..2a0d42a9f45 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -270,7 +270,6 @@ int ctdb_sock_addr_from_string(const char *str,
char *p;
char s[64]; /* Much longer than INET6_ADDRSTRLEN */
unsigned port;
- char *endp = NULL;
size_t len;
int ret;
@@ -291,8 +290,8 @@ int ctdb_sock_addr_from_string(const char *str,
return EINVAL;
}
- port = strtoul_err(p+1, &endp, 10, &ret);
- if (ret != 0 || *endp != '\0') {
+ port = smb_strtoul(p+1, NULL, 10, &ret, SMB_STR_FULL_STR_CONV);
+ if (ret != 0) {
/* Empty string or trailing garbage */
return EINVAL;
}
@@ -312,7 +311,6 @@ int ctdb_sock_addr_mask_from_string(const char *str,
char *p;
char s[64]; /* Much longer than INET6_ADDRSTRLEN */
unsigned int m;
- char *endp = NULL;
ssize_t len;
int ret = 0;
@@ -330,8 +328,8 @@ int ctdb_sock_addr_mask_from_string(const char *str,
return EINVAL;
}
- m = strtoul_err(p+1, &endp, 10, &ret);
- if (ret != 0 || *endp != '\0') {
+ m = smb_strtoul(p+1, NULL, 10, &ret, SMB_STR_FULL_STR_CONV);
+ if (ret != 0) {
/* Empty string or trailing garbage */
return EINVAL;
}
diff --git a/ctdb/server/ctdb_recovery_helper.c b/ctdb/server/ctdb_recovery_helper.c
index f2ea9b1fd56..0597c507ba6 100644
--- a/ctdb/server/ctdb_recovery_helper.c
+++ b/ctdb/server/ctdb_recovery_helper.c
@@ -2752,7 +2752,11 @@ int main(int argc, char *argv[])
write_fd = atoi(argv[1]);
sockpath = argv[2];
- generation = (uint32_t)strtoul_err(argv[3], NULL, 0, &ret);
+ generation = (uint32_t)smb_strtoul(argv[3],
+ NULL,
+ 0,
+ &ret,
+ SMB_STR_STANDARD);
if (ret != 0) {
fprintf(stderr, "recovery: unable to initialize generation\n");
goto failed;
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index d79945460f9..9d46c981a0f 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -326,7 +326,11 @@ static bool parse_nodestring(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
while (tok != NULL) {
uint32_t pnn;
- pnn = (uint32_t)strtoul_err(tok, NULL, 0, &error);
+ pnn = (uint32_t)smb_strtoul(tok,
+ NULL,
+ 0,
+ &error,
+ SMB_STR_STANDARD);
if (error != 0) {
fprintf(stderr, "Invalid node %s\n", tok);
return false;
@@ -546,7 +550,7 @@ static bool db_exists(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
}
if (strncmp(db_arg, "0x", 2) == 0) {
- id = strtoul_err(db_arg, NULL, 0, &ret);
+ id = smb_strtoul(db_arg, NULL, 0, &ret, SMB_STR_STANDARD);
if (ret != 0) {
return false;
}
@@ -1096,7 +1100,7 @@ static int control_setvar(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
}
tunable.name = argv[0];
- tunable.value = strtoul_err(argv[1], NULL, 0, &ret);
+ tunable.value = smb_strtoul(argv[1], NULL, 0, &ret, SMB_STR_STANDARD);
if (ret != 0) {
return ret;
}
@@ -1891,7 +1895,7 @@ static int control_process_exists(TALLOC_CTX *mem_ctx,
pid = atoi(argv[0]);
if (argc == 2) {
- srvid = strtoull_err(argv[1], NULL, 0, &ret);
+ srvid = smb_strtoull(argv[1], NULL, 0, &ret, SMB_STR_STANDARD);
if (ret != 0) {
return ret;
}
@@ -2802,7 +2806,7 @@ static int control_ban(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
}
ban_state.pnn = ctdb->cmd_pnn;
- ban_state.time = strtoul_err(argv[0], NULL, 0, &ret);
+ ban_state.time = smb_strtoul(argv[0], NULL, 0, &ret, SMB_STR_STANDARD);
if (ret != 0) {
return ret;
}
@@ -3126,7 +3130,7 @@ static int control_gettickles(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
}
if (argc == 2) {
- port = strtoul_err(argv[1], NULL, 10, &ret);
+ port = smb_strtoul(argv[1], NULL, 10, &ret, SMB_STR_STANDARD);
if (ret != 0) {
return ret;
}
@@ -3837,7 +3841,7 @@ static int control_moveip(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
return 1;
}
- pnn = strtoul_err(argv[1], NULL, 10, &ret);
+ pnn = smb_strtoul(argv[1], NULL, 10, &ret, SMB_STR_STANDARD);
if (pnn == CTDB_UNKNOWN_PNN || ret != 0) {
fprintf(stderr, "Invalid PNN %s\n", argv[1]);
return 1;
@@ -5294,7 +5298,11 @@ static int control_tstore(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
ZERO_STRUCT(header);
if (argc > 3) {
- header.rsn = (uint64_t)strtoull_err(argv[3], NULL, 0, &ret);
+ header.rsn = (uint64_t)smb_strtoull(argv[3],
+ NULL,
+ 0,
+ &ret,
+ SMB_STR_STANDARD);
if (ret != 0) {
return ret;
}
@@ -6311,7 +6319,11 @@ int main(int argc, const char *argv[])
ctdb_timeout = getenv("CTDB_TIMEOUT");
if (ctdb_timeout != NULL) {
- options.maxruntime = strtoul_err(ctdb_timeout, NULL, 0, &ret);
+ options.maxruntime = smb_strtoul(ctdb_timeout,
+ NULL,
+ 0,
+ &ret,
+ SMB_STR_STANDARD);
if (ret != 0) {
fprintf(stderr, "Invalid value CTDB_TIMEOUT\n");
exit(1);
diff --git a/lib/ldb-samba/ldb_matching_rules.c b/lib/ldb-samba/ldb_matching_rules.c
index 0754e7e066b..4b357bb706a 100644
--- a/lib/ldb-samba/ldb_matching_rules.c
+++ b/lib/ldb-samba/ldb_matching_rules.c
@@ -382,7 +382,6 @@ static int dsdb_match_for_dns_to_tombstone_time(struct ldb_context *ldb,
DBG_ERR("Invalid timestamp passed\n");
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
} else {
- char *p = NULL;
int error = 0;
char s[value_to_match->length+1];
@@ -392,8 +391,12 @@ static int dsdb_match_for_dns_to_tombstone_time(struct ldb_context *ldb,
DBG_ERR("Empty timestamp passed\n");
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
- tombstone_time = strtoull_err(s, &p, 10, &error);
- if (error != 0 || *p != '\0') {
+ tombstone_time = smb_strtoull(s,
+ NULL,
+ 10,
+ &error,
+ SMB_STR_FULL_STR_CONV);
+ if (error != 0) {
DBG_ERR("Invalid timestamp string passed\n");
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
@@ -514,7 +517,6 @@ static int dsdb_match_for_expunge(struct ldb_context *ldb,
if (value_to_match->length >=64) {
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
} else {
- char *p = NULL;
int error = 0;
char s[value_to_match->length+1];
@@ -523,8 +525,12 @@ static int dsdb_match_for_expunge(struct ldb_context *ldb,
if (s[0] == '\0' || s[0] == '-') {
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
- tombstone_time = strtoull_err(s, &p, 10, &error);
- if (error != 0 || *p != '\0') {
+ tombstone_time = smb_strtoull(s,
+ NULL,
+ 10,
+ &error,
+ SMB_STR_FULL_STR_CONV);
+ if (error != 0) {
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
}
diff --git a/lib/ldb-samba/ldif_handlers.c b/lib/ldb-samba/ldif_handlers.c
index 23d0860dd9b..e74a7182ecf 100644
--- a/lib/ldb-samba/ldif_handlers.c
+++ b/lib/ldb-samba/ldif_handlers.c
@@ -622,7 +622,7 @@ static int ldif_read_prefixMap(struct ldb_context *ldb, void *mem_ctx,
}
blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].id_prefix =
- strtoul_err(line, &oid, 10, &error);
+ smb_strtoul(line, &oid, 10, &error, SMB_STR_STANDARD);
if (oid[0] != ':' || error != 0) {
talloc_free(tmp_ctx);
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 169d884ec04..413e0237800 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -339,7 +339,7 @@ unsigned long lp_ulong(const char *s)
return -1;
}
- ret = strtoul_err(s, NULL, 0, &error);
+ ret = smb_strtoul(s, NULL, 0, &error, SMB_STR_STANDARD);
if (error != 0) {
DBG_DEBUG("lp_ulong(%s): conversion failed\n",s);
return -1;
@@ -361,7 +361,7 @@ unsigned long long lp_ulonglong(const char *s)
return -1;
}
- ret = strtoull_err(s, NULL, 0, &error);
+ ret = smb_strtoull(s, NULL, 0, &error, SMB_STR_STANDARD);
if (error != 0) {
DBG_DEBUG("lp_ulonglong(%s): conversion failed\n",s);
return -1;
diff --git a/lib/util/access.c b/lib/util/access.c
index 960fe4b066c..10a14771899 100644
--- a/lib/util/access.c
+++ b/lib/util/access.c
@@ -70,12 +70,15 @@ static bool masked_match(const char *tok, const char *slash, const char *s)
return false;
}
} else {
- char *endp = NULL;
int error = 0;
unsigned long val;
- val = strtoul_err(slash+1, &endp, 0, &error);
- if (error != 0 || *endp != '\0') {
+ val = smb_strtoul(slash+1,
+ NULL,
+ 0,
+ &error,
+ SMB_STR_FULL_STR_CONV);
+ if (error != 0) {
return false;
}
if (!make_netmask(&ss_mask, &ss_tok, val)) {
diff --git a/lib/util/asn1.c b/lib/util/asn1.c
index 70ff5f0ad88..51da5424956 100644
--- a/lib/util/asn1.c
+++ b/lib/util/asn1.c
@@ -278,14 +278,14 @@ bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
int error = 0;
if (!isdigit(*p)) return false;
- v = strtoul_err(p, &newp, 10, &error);
+ v = smb_strtoul(p, &newp, 10, &error, SMB_STR_STANDARD);
if (newp[0] != '.' || error != 0) {
return false;
}
p = newp + 1;
if (!isdigit(*p)) return false;
- v2 = strtoul_err(p, &newp, 10, &error);
+ v2 = smb_strtoul(p, &newp, 10, &error, SMB_STR_STANDARD);
if (newp[0] != '.' || error != 0) {
return false;
}
@@ -300,7 +300,7 @@ bool ber_write_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *OID)
i = 1;
while (*p) {
if (!isdigit(*p)) return false;
- v = strtoul_err(p, &newp, 10, &error);
+ v = smb_strtoul(p, &newp, 10, &error, SMB_STR_STANDARD);
if (newp[0] == '.' || error != 0) {
p = newp + 1;
/* check for empty last component */
diff --git a/lib/util/tests/util.c b/lib/util/tests/util.c
index ad9c6606e59..4876144bcdc 100644
--- a/lib/util/tests/util.c
+++ b/lib/util/tests/util.c
@@ -3,6 +3,7 @@
*
* Copyright Martin Schwenke <martin at meltin.net> 2016
* Copyright Christof Schmitt <cs at samba.org> 2018
+ * Copyright Swen Schillig <swen at linux.ibm.com> 2019
*
* 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
@@ -30,6 +31,9 @@
#include "lib/util/samba_util.h"
+#include "limits.h"
+#include "string.h"
+
struct test_trim_string_data {
const char *desc;
const char *in;
@@ -421,6 +425,177 @@ done:
return ret;
}
+static bool test_smb_strtoul_errno_check(struct torture_context *tctx)
+{
+ const char *number = "123";
+ unsigned long int val = 0;
+ unsigned long long int vall = 0;
+ int err;
+
+ /* select an error code which is not set by the smb_strtoul routines */
+ errno = EAGAIN;
+ err = EAGAIN;
+ val = smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, errno == EAGAIN, "smb_strtoul: Expected EAGAIN");
+ torture_assert(tctx, err == 0, "smb_strtoul: Expected err = 0");
+ torture_assert(tctx, val == 123, "smb_strtoul: Expected value 123");
+
+ /* set err to an impossible value again before continuing */
+ err = EAGAIN;
+ vall = smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, errno == EAGAIN, "smb_strtoull: Expected EAGAIN");
+ torture_assert(tctx, err == 0, "smb_strtoul: Expected err = 0");
+ torture_assert(tctx, vall == 123, "smb_strtoul: Expected value 123");
+
+ return true;
+}
+
+static bool test_smb_strtoul_negative(struct torture_context *tctx)
+{
+ const char *number = "-132";
+ const char *number2 = "132-";
+ unsigned long int val = 0;
+ unsigned long long int vall = 0;
+ int err;
+
+ err = 0;
+ smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
+
+ err = 0;
+ smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
+
+ /* it is allowed to have a "-" sign after a number,
+ * e.g. as part of a formular, however, it is not supposed to
+ * have an effect on the converted value.
+ */
+
+ err = 0;
+ val = smb_strtoul(number2, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == 0, "smb_strtoul: Expected no error");
+ torture_assert(tctx, val == 132, "smb_strtoul: Wrong value");
+
+ err = 0;
+ vall = smb_strtoull(number2, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == 0, "smb_strtoull: Expected no error");
+ torture_assert(tctx, vall == 132, "smb_strtoull: Wrong value");
+
+ return true;
+}
+
+static bool test_smb_strtoul_no_number(struct torture_context *tctx)
+{
+ const char *number = "ghijk";
+ const char *blank = "";
+ int err;
+
+ err = 0;
+ smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
+
+ err = 0;
+ smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
+
+ err = 0;
+ smb_strtoul(blank, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
+
+ err = 0;
+ smb_strtoull(blank, NULL, 0, &err, SMB_STR_STANDARD);
+ torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
+
+ return true;
+}
+
+static bool test_smb_strtoul_allow_negative(struct torture_context *tctx)
+{
+ const char *number = "-1";
+ const char *number2 = "-1-1";
+ unsigned long res = 0;
+ unsigned long long res2 = 0;
+ char *end_ptr = NULL;
+ int err;
+
+ err = 0;
+ res = smb_strtoul(number, NULL, 0, &err, SMB_STR_ALLOW_NEGATIVE);
+ torture_assert(tctx, err == 0, "strtoul_err: Unexpected error");
+ torture_assert(tctx, res == ULONG_MAX, "strtoul_err: Unexpected value");
+
+ err = 0;
+ res2 = smb_strtoull(number, NULL, 0, &err, SMB_STR_ALLOW_NEGATIVE);
+ torture_assert(tctx, err == 0, "strtoull_err: Unexpected error");
+ torture_assert(tctx, res2 == ULLONG_MAX, "strtoull_err: Unexpected value");
+
+ err = 0;
+ smb_strtoul(number2, &end_ptr, 0, &err, SMB_STR_ALLOW_NEGATIVE);
+ torture_assert(tctx, err == 0, "strtoul_err: Unexpected error");
+ torture_assert(tctx, end_ptr[0] == '-', "strtoul_err: Unexpected end pointer");
+
+ err = 0;
+ smb_strtoull(number2, &end_ptr, 0, &err, SMB_STR_ALLOW_NEGATIVE);
+ torture_assert(tctx, err == 0, "strtoull_err: Unexpected error");
+ torture_assert(tctx, end_ptr[0] == '-', "strtoull_err: Unexpected end pointer");
+
+ return true;
+}
+
+static bool test_smb_strtoul_full_string(struct torture_context *tctx)
+{
+ const char *number = "123 ";
+ const char *number2 = "123";
+ int err;
+
+ err = 0;
+ smb_strtoul(number, NULL, 0, &err, SMB_STR_FULL_STR_CONV);
+ torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
+
+ err = 0;
+ smb_strtoull(number, NULL, 0, &err, SMB_STR_FULL_STR_CONV);
+ torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
+
+ err = 0;
+ smb_strtoul(number2, NULL, 0, &err, SMB_STR_FULL_STR_CONV);
+ torture_assert(tctx, err == 0, "strtoul_err: Unexpected error");
+
+ err = 0;
+ smb_strtoull(number2, NULL, 0, &err, SMB_STR_FULL_STR_CONV);
+ torture_assert(tctx, err == 0, "strtoull_err: Unexpected error");
+
+ return true;
+}
+
+static bool test_smb_strtoul_allow_no_conversion(struct torture_context *tctx)
+{
+ const char *number = "";
+ const char *number2 = "xyz";
+ unsigned long int n1 = 0;
+ unsigned long long int n2 = 0;
+ int err;
+
+ err = 0;
+ smb_strtoul(number, NULL, 0, &err, SMB_STR_ALLOW_NO_CONVERSION);
+ torture_assert(tctx, err == 0, "strtoul_err: Unexpected error");
+ torture_assert(tctx, n1 == 0, "strtoul_err: Unexpected value");
+
+ err = 0;
+ smb_strtoull(number, NULL, 0, &err, SMB_STR_ALLOW_NO_CONVERSION);
+ torture_assert(tctx, err == 0, "strtoull_err: Unexpected error");
+ torture_assert(tctx, n2 == 0, "strtoull_err: Unexpected value");
+
+ err = 0;
+ smb_strtoul(number2, NULL, 0, &err, SMB_STR_ALLOW_NO_CONVERSION);
+ torture_assert(tctx, err == 0, "strtoul_err: Unexpected error");
+ torture_assert(tctx, n1 == 0, "strtoul_err: Unexpected value");
+
+ err = 0;
+ smb_strtoull(number2, NULL, 0, &err, SMB_STR_ALLOW_NO_CONVERSION);
+ torture_assert(tctx, err == 0, "strtoull_err: Unexpected error");
+ torture_assert(tctx, n2 == 0, "strtoull_err: Unexpected value");
+
+ return true;
+}
struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx)
{
struct torture_suite *suite =
@@ -432,5 +607,23 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx)
torture_suite_add_simple_test(suite,
"directory_create_or_exist",
test_directory_create_or_exist);
+ torture_suite_add_simple_test(suite,
+ "smb_strtoul(l) errno",
--
Samba Shared Repository
More information about the samba-cvs
mailing list