lib: Update all consumers of strtoul_err(), strtoull_err() to new API
authorSwen Schillig <swen@linux.ibm.com>
Tue, 4 Jun 2019 06:57:03 +0000 (08:57 +0200)
committerRalph Boehme <slow@samba.org>
Sun, 30 Jun 2019 11:32:18 +0000 (11:32 +0000)
Signed-off-by: Swen Schillig <swen@linux.ibm.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
lib/ldb-samba/ldb_matching_rules.c
lib/ldb-samba/ldif_handlers.c
lib/param/loadparm.c
lib/util/access.c
lib/util/asn1.c
lib/util/tests/util.c
lib/util/util_str.c

index 0754e7e066be3df2ca98613a992ccca061320154..4b357bb706a65f34bb378d98b7f838a474608725 100644 (file)
@@ -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;
                }
        }
index 23d0860dd9b83081f278a66065b27c922f1a83c0..e74a7182ecf0e55c90dc1e5427392bedb699e29c 100644 (file)
@@ -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);
index 169d884ec04cdce9191b71387ffe4170d12544c6..413e023780019da9c3944aea4f0bdfcf521afd68 100644 (file)
@@ -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;
index 960fe4b066cad6197ccbdad7aefdd730911bb753..10a147718995853b7d0661852d2f0e2e1183fc3a 100644 (file)
@@ -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)) {
index 70ff5f0ad8854bfbce41b624e97bad95dfc1c246..51da5424956672dec42e08213f4a4af90129f1f1 100644 (file)
@@ -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 */
index de9dca1ffc57efabf035d6f37d06f152fdb92b94..854d1d2023fcb3bd952f2938b1f9a15b02a93d8d 100644 (file)
@@ -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;
 }
index 29a44836bdea4f5e6af6918280ee6909778bf85b..3356df34f04f1bbcb6710a35e4181e860d04bb63 100644 (file)
@@ -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;
        }