mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Fix coverity issues in client CLI tools
This patch fixes 2 coverity issues: * ipa-client/config.c: CID 11090: Resource leak * ipa-client/ipa-getkeytab.c: CID 11018: Unchecked return value https://fedorahosted.org/freeipa/ticket/2035
This commit is contained in:
parent
d24dda2fe3
commit
216505d2a0
@ -45,28 +45,29 @@
|
|||||||
char *
|
char *
|
||||||
read_config_file(const char *filename)
|
read_config_file(const char *filename)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = -1;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *data, *dest;
|
char *data = NULL;
|
||||||
|
char *dest;
|
||||||
size_t left;
|
size_t left;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY);
|
fd = open(filename, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
fprintf(stderr, _("cannot open configuration file %s\n"), filename);
|
fprintf(stderr, _("cannot open configuration file %s\n"), filename);
|
||||||
return NULL;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* stat() the file so we know the size and can pre-allocate the right
|
/* stat() the file so we know the size and can pre-allocate the right
|
||||||
* amount of memory. */
|
* amount of memory. */
|
||||||
if (fstat(fd, &st) == -1) {
|
if (fstat(fd, &st) == -1) {
|
||||||
fprintf(stderr, _("cannot stat() configuration file %s\n"), filename);
|
fprintf(stderr, _("cannot stat() configuration file %s\n"), filename);
|
||||||
return NULL;
|
goto error_out;
|
||||||
}
|
}
|
||||||
left = st.st_size;
|
left = st.st_size;
|
||||||
data = malloc(st.st_size + 1);
|
data = malloc(st.st_size + 1);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
fprintf(stderr, _("out of memory\n"));
|
fprintf(stderr, _("out of memory\n"));
|
||||||
return NULL;
|
goto error_out;
|
||||||
}
|
}
|
||||||
dest = data;
|
dest = data;
|
||||||
while (left != 0) {
|
while (left != 0) {
|
||||||
@ -77,9 +78,7 @@ read_config_file(const char *filename)
|
|||||||
break;
|
break;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
fprintf(stderr, _("read error\n"));
|
fprintf(stderr, _("read error\n"));
|
||||||
close(fd);
|
goto error_out;
|
||||||
free(dest);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
dest += res;
|
dest += res;
|
||||||
left -= res;
|
left -= res;
|
||||||
@ -87,6 +86,11 @@ read_config_file(const char *filename)
|
|||||||
close(fd);
|
close(fd);
|
||||||
*dest = 0;
|
*dest = 0;
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
|
error_out:
|
||||||
|
if (fd != -1) close(fd);
|
||||||
|
free(data);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -82,14 +82,24 @@ static int ldap_sasl_interact(LDAP *ld, unsigned flags, void *priv_data, void *s
|
|||||||
krberr = krb5_init_context(&krbctx);
|
krberr = krb5_init_context(&krbctx);
|
||||||
|
|
||||||
if (krberr) {
|
if (krberr) {
|
||||||
fprintf(stderr, _("Kerberos context initialization failed\n"));
|
fprintf(stderr, _("Kerberos context initialization failed: %s (%d)\n"),
|
||||||
|
error_message(krberr), krberr);
|
||||||
in->result = NULL;
|
in->result = NULL;
|
||||||
in->len = 0;
|
in->len = 0;
|
||||||
ret = LDAP_LOCAL_ERROR;
|
ret = LDAP_LOCAL_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
krb5_unparse_name(krbctx, princ, &outname);
|
krberr = krb5_unparse_name(krbctx, princ, &outname);
|
||||||
|
|
||||||
|
if (krberr) {
|
||||||
|
fprintf(stderr, _("Unable to parse principal: %s (%d)\n"),
|
||||||
|
error_message(krberr), krberr);
|
||||||
|
in->result = NULL;
|
||||||
|
in->len = 0;
|
||||||
|
ret = LDAP_LOCAL_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
in->result = outname;
|
in->result = outname;
|
||||||
in->len = strlen(outname);
|
in->len = strlen(outname);
|
||||||
|
Loading…
Reference in New Issue
Block a user