mirror of
https://github.com/samba-team/samba.git
synced 2025-02-22 05:57:43 +03:00
lib: Update all consumers of strtoul_err(), strtoull_err() to new API
Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
This commit is contained in:
parent
73640b8ad8
commit
a8bbd60fd9
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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)) {
|
||||
|
@ -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 */
|
||||
|
@ -422,32 +422,32 @@ done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool test_strtoul_err_errno_check(struct torture_context *tctx)
|
||||
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 strtoul_err routines */
|
||||
/* select an error code which is not set by the smb_strtoul routines */
|
||||
errno = EAGAIN;
|
||||
err = EAGAIN;
|
||||
val = strtoul_err(number, NULL, 0, &err);
|
||||
torture_assert(tctx, errno == EAGAIN, "strtoul_err: Expected EAGAIN");
|
||||
torture_assert(tctx, err == 0, "strtoul_err: Expected err = 0");
|
||||
torture_assert(tctx, val == 123, "strtoul_err: Expected value 123");
|
||||
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 = strtoull_err(number, NULL, 0, &err);
|
||||
torture_assert(tctx, errno == EAGAIN, "strtoull_err: Expected EAGAIN");
|
||||
torture_assert(tctx, err == 0, "strtoul_err: Expected err = 0");
|
||||
torture_assert(tctx, vall == 123, "strtoul_err: Expected value 123");
|
||||
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_strtoul_err_negative(struct torture_context *tctx)
|
||||
static bool test_smb_strtoul_negative(struct torture_context *tctx)
|
||||
{
|
||||
const char *number = "-132";
|
||||
const char *number2 = "132-";
|
||||
@ -456,12 +456,12 @@ static bool test_strtoul_err_negative(struct torture_context *tctx)
|
||||
int err;
|
||||
|
||||
err = 0;
|
||||
strtoul_err(number, NULL, 0, &err);
|
||||
torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
|
||||
smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
|
||||
torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
|
||||
|
||||
err = 0;
|
||||
strtoull_err(number, NULL, 0, &err);
|
||||
torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
|
||||
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
|
||||
@ -469,39 +469,39 @@ static bool test_strtoul_err_negative(struct torture_context *tctx)
|
||||
*/
|
||||
|
||||
err = 0;
|
||||
val = strtoul_err(number2, NULL, 0, &err);
|
||||
torture_assert(tctx, err == 0, "strtoul_err: Expected no error");
|
||||
torture_assert(tctx, val == 132, "strtoul_err: Wrong value");
|
||||
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 = strtoull_err(number2, NULL, 0, &err);
|
||||
torture_assert(tctx, err == 0, "strtoull_err: Expected no error");
|
||||
torture_assert(tctx, vall == 132, "strtoull_err: Wrong value");
|
||||
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_strtoul_err_no_number(struct torture_context *tctx)
|
||||
static bool test_smb_strtoul_no_number(struct torture_context *tctx)
|
||||
{
|
||||
const char *number = "ghijk";
|
||||
const char *blank = "";
|
||||
int err;
|
||||
|
||||
err = 0;
|
||||
strtoul_err(number, NULL, 0, &err);
|
||||
torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
|
||||
smb_strtoul(number, NULL, 0, &err, SMB_STR_STANDARD);
|
||||
torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
|
||||
|
||||
err = 0;
|
||||
strtoull_err(number, NULL, 0, &err);
|
||||
torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
|
||||
smb_strtoull(number, NULL, 0, &err, SMB_STR_STANDARD);
|
||||
torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
|
||||
|
||||
err = 0;
|
||||
strtoul_err(blank, NULL, 0, &err);
|
||||
torture_assert(tctx, err == EINVAL, "strtoul_err: Expected EINVAL");
|
||||
smb_strtoul(blank, NULL, 0, &err, SMB_STR_STANDARD);
|
||||
torture_assert(tctx, err == EINVAL, "smb_strtoul: Expected EINVAL");
|
||||
|
||||
err = 0;
|
||||
strtoull_err(blank, NULL, 0, &err);
|
||||
torture_assert(tctx, err == EINVAL, "strtoull_err: Expected EINVAL");
|
||||
smb_strtoull(blank, NULL, 0, &err, SMB_STR_STANDARD);
|
||||
torture_assert(tctx, err == EINVAL, "smb_strtoull: Expected EINVAL");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -518,13 +518,13 @@ struct torture_suite *torture_local_util(TALLOC_CTX *mem_ctx)
|
||||
"directory_create_or_exist",
|
||||
test_directory_create_or_exist);
|
||||
torture_suite_add_simple_test(suite,
|
||||
"strtoul(l)_err errno",
|
||||
test_strtoul_err_errno_check);
|
||||
"smb_strtoul(l) errno",
|
||||
test_smb_strtoul_errno_check);
|
||||
torture_suite_add_simple_test(suite,
|
||||
"strtoul(l)_err negative",
|
||||
test_strtoul_err_negative);
|
||||
"smb_strtoul(l) negative",
|
||||
test_smb_strtoul_negative);
|
||||
torture_suite_add_simple_test(suite,
|
||||
"strtoul(l)_err no number",
|
||||
test_strtoul_err_no_number);
|
||||
"smb_strtoul(l) no number",
|
||||
test_smb_strtoul_no_number);
|
||||
return suite;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ _PUBLIC_ bool conv_str_size_error(const char * str, uint64_t * val)
|
||||
return false;
|
||||
}
|
||||
|
||||
lval = strtoull_err(str, &end, 10, &error);
|
||||
lval = smb_strtoull(str, &end, 10, &error, SMB_STR_STANDARD);
|
||||
if (error != 0) {
|
||||
return false;
|
||||
}
|
||||
@ -103,7 +103,6 @@ _PUBLIC_ bool conv_str_size_error(const char * str, uint64_t * val)
|
||||
*/
|
||||
_PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val)
|
||||
{
|
||||
char * end = NULL;
|
||||
unsigned long long lval;
|
||||
int error = 0;
|
||||
|
||||
@ -111,8 +110,8 @@ _PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val)
|
||||
return false;
|
||||
}
|
||||
|
||||
lval = strtoull_err(str, &end, 10, &error);
|
||||
if (error != 0 || *end != '\0') {
|
||||
lval = smb_strtoull(str, NULL, 10, &error, SMB_STR_FULL_STR_CONV);
|
||||
if (error != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user