Skip to content

Commit

Permalink
KCM: sss_iobuf_init_empty() shall not zero memory
Browse files Browse the repository at this point in the history
sss_iobuf_init_empty() and related functions zero the allocated memory
even though it is not needed. Most of the time, all the fields in the
structures will be set to non-zero values. In these cases zeroing the
is useless and we stop doing it.

Only in two cases, some pointers were being left unmodified, so they
are now being manually set to NULL.

Resolves: SSSD#7014
  • Loading branch information
aplopez committed Nov 13, 2023
1 parent 1491463 commit 78bd787
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/responder/kcm/kcmsrv_ccache.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ struct kcm_cred *kcm_cred_new(TALLOC_CTX *mem_ctx,
if (kcreds == NULL) {
return NULL;
}

uuid_copy(kcreds->uuid, uuid);
kcreds->cred_blob = talloc_steal(kcreds, cred_blob);
return kcreds;
Expand Down
7 changes: 4 additions & 3 deletions src/util/sss_iobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct sss_iobuf {
size_t capacity; /* Maximum capacity */
};

/* The allocated buffer (iobuf->data) will not be zeroed. */
struct sss_iobuf *sss_iobuf_init_empty(TALLOC_CTX *mem_ctx,
size_t size,
size_t capacity)
Expand All @@ -30,7 +31,7 @@ struct sss_iobuf *sss_iobuf_init_empty(TALLOC_CTX *mem_ctx,
return NULL;
}

buf = talloc_zero_array(iobuf, uint8_t, size);
buf = talloc_array(iobuf, uint8_t, size);
if (buf == NULL) {
talloc_free(iobuf);
return NULL;
Expand All @@ -43,11 +44,12 @@ struct sss_iobuf *sss_iobuf_init_empty(TALLOC_CTX *mem_ctx,
iobuf->data = buf;
iobuf->size = size;
iobuf->capacity = capacity;
iobuf->dp = 0;

return iobuf;
}

/* The allocated buffer (iobuf->data) will not be zeroed
* if data is not provided. */
struct sss_iobuf *sss_iobuf_init_readonly(TALLOC_CTX *mem_ctx,
const uint8_t *data,
size_t size)
Expand Down Expand Up @@ -80,7 +82,6 @@ struct sss_iobuf *sss_iobuf_init_steal(TALLOC_CTX *mem_ctx,
iobuf->data = talloc_steal(iobuf, data);
iobuf->size = size;
iobuf->capacity = size;
iobuf->dp = 0;

return iobuf;
}
Expand Down

0 comments on commit 78bd787

Please sign in to comment.