util/charset/iconv: use read_hex_bytes rather than sscanf
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 22 Mar 2018 04:54:55 +0000 (17:54 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 30 May 2018 23:57:16 +0000 (01:57 +0200)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/charset/iconv.c

index 02c061ccd09403190338cd513a2300f794eb5879..a03ff20b8cc9a46426b882317c38819a55afcd43 100644 (file)
@@ -25,6 +25,8 @@
 #include "lib/util/dlinklist.h"
 #include "lib/util/charset/charset.h"
 #include "lib/util/charset/charset_proto.h"
+#include "libcli/util/ntstatus.h"
+#include "lib/util/util_str_hex.h"
 
 #ifdef strcasecmp
 #undef strcasecmp
@@ -454,8 +456,8 @@ static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft,
                         char **outbuf, size_t *outbytesleft)
 {
        while (*inbytesleft >= 1 && *outbytesleft >= 2) {
-               unsigned int v;
-
+               uint64_t v;
+               NTSTATUS status;
                if ((*inbuf)[0] != '@') {
                        /* seven bit ascii case */
                        (*outbuf)[0] = (*inbuf)[0];
@@ -471,8 +473,9 @@ static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft,
                        errno = EINVAL;
                        return -1;
                }
+               status = read_hex_bytes(&(*inbuf)[1], 4, &v);
 
-               if (sscanf(&(*inbuf)[1], "%04x", &v) != 1) {
+               if (!NT_STATUS_IS_OK(status)) {
                        errno = EILSEQ;
                        return -1;
                }