Skip to content

Commit

Permalink
libcli: Use wrapper for string to integer conversion
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ralph Böhme <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
sswen authored and jrasamba committed Mar 1, 2019
1 parent e7b7c63 commit 58e2c15
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libcli/security/dom_sid.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "lib/util/data_blob.h"
#include "system/locale.h"
#include "lib/util/debug.h"
#include "lib/util/util.h"
#include "librpc/gen_ndr/security.h"
#include "dom_sid.h"

Expand Down Expand Up @@ -132,6 +133,7 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
char *q;
/* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 */
uint64_t conv;
int error = 0;

ZERO_STRUCTP(sidout);

Expand All @@ -146,8 +148,8 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
goto format_error;
}

conv = strtoul(p, &q, 10);
if (!q || (*q != '-') || conv > UINT8_MAX) {
conv = strtoul_err(p, &q, 10, &error);
if (!q || (*q != '-') || conv > UINT8_MAX || error != 0) {
goto format_error;
}
sidout->sid_rev_num = (uint8_t) conv;
Expand All @@ -158,8 +160,8 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
}

/* get identauth */
conv = strtoull(q, &q, 0);
if (!q || conv & AUTHORITY_MASK) {
conv = strtoull_err(q, &q, 0, &error);
if (!q || conv & AUTHORITY_MASK || error != 0) {
goto format_error;
}

Expand Down Expand Up @@ -187,8 +189,8 @@ bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout,
goto format_error;
}

conv = strtoull(q, &end, 10);
if (end == q || conv > UINT32_MAX) {
conv = strtoull_err(q, &end, 10, &error);
if (end == q || conv > UINT32_MAX || error != 0) {
goto format_error;
}

Expand Down

0 comments on commit 58e2c15

Please sign in to comment.