rpcclient: Use wrapper for string to integer conversion
authorSwen Schillig <swen@linux.ibm.com>
Mon, 28 Jan 2019 13:35:30 +0000 (14:35 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 1 Mar 2019 00:32:10 +0000 (00:32 +0000)
In order to detect an value overflow error during
the string to integer conversion with strtoul/strtoull,
the errno variable must be set to zero before the execution and
checked after the conversion is performed. This is achieved by
using the wrapper function strtoul_err and strtoull_err.

Signed-off-by: Swen Schillig <swen@linux.ibm.com>
Reviewed-by: Ralph Böhme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/rpcclient/cmd_samr.c
source3/rpcclient/cmd_spoolss.c

index 7e396f92a4805ece6a6703b4a186cc19671027b6..898ae6ad6fca0a465bcb8a1c50d49f282a8d0f9e 100644 (file)
@@ -1406,13 +1406,18 @@ static NTSTATUS cmd_samr_delete_alias(struct rpc_pipe_client *cli,
        uint32_t alias_rid;
        uint32_t access_mask = MAXIMUM_ALLOWED_ACCESS;
        struct dcerpc_binding_handle *b = cli->binding_handle;
+       int error = 0;
 
        if (argc != 3) {
                printf("Usage: %s builtin|domain [rid|name]\n", argv[0]);
                return NT_STATUS_OK;
        }
 
-       alias_rid = strtoul(argv[2], NULL, 10);
+       alias_rid = strtoul_err(argv[2], NULL, 10, &error);
+       if (error != 0) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
 
        /* Open SAMR handle */
 
index 0a850ddc6aa82c9090cb42e9d6cded43a300b391..f6d631761b2ef3b9238e1b45c1fca977a26423a0 100644 (file)
@@ -2642,6 +2642,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
        union spoolss_PrinterData data;
        DATA_BLOB blob;
        struct dcerpc_binding_handle *b = cli->binding_handle;
+       int error = 0;
 
        /* parse the command arguments */
        if (argc < 5) {
@@ -2707,7 +2708,12 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
                W_ERROR_HAVE_NO_MEMORY(data.string);
                break;
        case REG_DWORD:
-               data.value = strtoul(argv[4], NULL, 10);
+               data.value = strtoul_err(argv[4], NULL, 10, &error);
+               if (error != 0) {
+                       result = WERR_INVALID_PARAMETER;
+                       goto done;
+               }
+
                break;
        case REG_BINARY:
                data.binary = strhex_to_data_blob(mem_ctx, argv[4]);