summaryrefslogtreecommitdiff
path: root/libcli
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2018-11-01 11:11:17 +0100
committerJeremy Allison <jra@samba.org>2018-11-02 17:03:26 +0100
commit831ee63f54959168cf34f12d4590102f40448cc5 (patch)
tree4fabdfa0231c18c370bad970ddc63ccc86b0463d /libcli
parent537a26d6d1d1c04456ec0f0b28f04a7de86af027 (diff)
downloadsamba-831ee63f54959168cf34f12d4590102f40448cc5.tar.gz
lib: Add error checks in dom_sid_string_buf
Also, avoid casts by using PRIxxx macros Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'libcli')
-rw-r--r--libcli/security/dom_sid.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/libcli/security/dom_sid.c b/libcli/security/dom_sid.c
index b876fc8b780..d913f2d93fb 100644
--- a/libcli/security/dom_sid.c
+++ b/libcli/security/dom_sid.c
@@ -431,7 +431,7 @@ bool dom_sid_is_valid_account_domain(const struct dom_sid *sid)
*/
int dom_sid_string_buf(const struct dom_sid *sid, char *buf, int buflen)
{
- int i, ofs;
+ int i, ofs, ret;
uint64_t ia;
if (!sid) {
@@ -445,18 +445,32 @@ int dom_sid_string_buf(const struct dom_sid *sid, char *buf, int buflen)
((uint64_t)sid->id_auth[1] << 32) +
((uint64_t)sid->id_auth[0] << 40);
- ofs = snprintf(buf, buflen, "S-%hhu-", (unsigned char)sid->sid_rev_num);
+ ret = snprintf(buf, buflen, "S-%"PRIu8"-", sid->sid_rev_num);
+ if (ret < 0) {
+ return ret;
+ }
+ ofs = ret;
+
if (ia >= UINT32_MAX) {
- ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "0x%llx",
- (unsigned long long)ia);
+ ret = snprintf(buf+ofs, MAX(buflen-ofs, 0), "0x%"PRIx64, ia);
} else {
- ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "%llu",
- (unsigned long long)ia);
+ ret = snprintf(buf+ofs, MAX(buflen-ofs, 0), "%"PRIu64, ia);
}
+ if (ret < 0) {
+ return ret;
+ }
+ ofs += ret;
for (i = 0; i < sid->num_auths; i++) {
- ofs += snprintf(buf + ofs, MAX(buflen - ofs, 0), "-%u",
- (unsigned int)sid->sub_auths[i]);
+ ret = snprintf(
+ buf+ofs,
+ MAX(buflen-ofs, 0),
+ "-%"PRIu32,
+ sid->sub_auths[i]);
+ if (ret < 0) {
+ return ret;
+ }
+ ofs += ret;
}
return ofs;
}
@@ -472,7 +486,7 @@ char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
len = dom_sid_string_buf(sid, buf, sizeof(buf));
- if (len+1 > sizeof(buf)) {
+ if ((len < 0) || (len+1 > sizeof(buf))) {
return talloc_strdup(mem_ctx, "(SID ERR)");
}