diff options
author | Sumit Bose <sbose@redhat.com> | 2010-12-14 22:44:24 +0100 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-12-14 17:13:30 -0500 |
commit | 5d6b7b93c778e22133f889690c3863c305c1e03f (patch) | |
tree | b028094d5cda12bf7b4972240a96c9808b014186 /src | |
parent | e404ac6b8c5b78a102e20320133706f5efa66b12 (diff) | |
download | sssd-5d6b7b93c778e22133f889690c3863c305c1e03f.tar.gz sssd-5d6b7b93c778e22133f889690c3863c305c1e03f.tar.bz2 sssd-5d6b7b93c778e22133f889690c3863c305c1e03f.zip |
Fix possible memory leak in sss_nss_recv_rep()
https://fedorahosted.org/sssd/ticket/723
Diffstat (limited to 'src')
-rw-r--r-- | src/sss_client/common.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/sss_client/common.c b/src/sss_client/common.c index 0efdbdf3..905c0df4 100644 --- a/src/sss_client/common.c +++ b/src/sss_client/common.c @@ -170,11 +170,13 @@ static enum nss_status sss_nss_send_req(enum sss_cli_command cmd, */ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd, - uint8_t **buf, int *len, + uint8_t **_buf, int *_len, int *errnop) { uint32_t header[4]; size_t datarecv; + uint8_t *buf; + int len; header[0] = SSS_NSS_HEADER_SIZE; /* unitl we know the real lenght */ header[1] = 0; @@ -182,8 +184,8 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd, header[3] = 0; datarecv = 0; - *buf = NULL; - *len = 0; + buf = NULL; + len = 0; *errnop = 0; while (datarecv < header[0]) { @@ -237,7 +239,7 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd, } else { bufrecv = datarecv - SSS_NSS_HEADER_SIZE; res = read(sss_cli_sd, - (char *)(*buf) + bufrecv, + (char *) buf + bufrecv, header[0] - datarecv); } error = errno; @@ -262,7 +264,7 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd, datarecv += res; - if (datarecv == SSS_NSS_HEADER_SIZE && *len == 0) { + if (datarecv == SSS_NSS_HEADER_SIZE && len == 0) { /* at this point recv buf is not yet * allocated and the header has just * been read, do checks and proceed */ @@ -283,9 +285,9 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd, return NSS_STATUS_UNAVAIL; } if (header[0] > SSS_NSS_HEADER_SIZE) { - *len = header[0] - SSS_NSS_HEADER_SIZE; - *buf = malloc(*len); - if (!*buf) { + len = header[0] - SSS_NSS_HEADER_SIZE; + buf = malloc(len); + if (!buf) { sss_cli_close_socket(); *errnop = ENOMEM; return NSS_STATUS_UNAVAIL; @@ -294,6 +296,9 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd, } } + *_len = len; + *_buf = buf; + return NSS_STATUS_SUCCESS; } |