mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
Fix memory leaks and non-null terminated strings usage
Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
@@ -120,8 +120,10 @@ GError *list(char *ref_label, char *** paths, char *** accts, unsigned int *list
|
|||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
char **tmp_paths = (char **) malloc((int)sizeof(char *)*numKeys);
|
|
||||||
char **tmp_accts = (char **) malloc((int)sizeof(char *)*numKeys);
|
char **tmp_paths = (char **) calloc(1,(int)sizeof(char *)*numKeys);
|
||||||
|
char **tmp_accts = (char **) calloc(1,(int)sizeof(char *)*numKeys);
|
||||||
|
|
||||||
// items now contains our keys from the gnome keyring
|
// items now contains our keys from the gnome keyring
|
||||||
// we will now put it in our two lists to return it to go
|
// we will now put it in our two lists to return it to go
|
||||||
GList *current;
|
GList *current;
|
||||||
@@ -133,23 +135,19 @@ GError *list(char *ref_label, char *** paths, char *** accts, unsigned int *list
|
|||||||
if (acctTmp==NULL) {
|
if (acctTmp==NULL) {
|
||||||
acctTmp = "account not defined";
|
acctTmp = "account not defined";
|
||||||
}
|
}
|
||||||
char *labelTmp = get_attribute("label", current->data);
|
|
||||||
if (strcmp(labelTmp, ref_label)) {
|
tmp_paths[listNumber] = (char *) calloc(1, sizeof(char)*(strlen(pathTmp)+1));
|
||||||
continue;
|
tmp_accts[listNumber] = (char *) calloc(1, sizeof(char)*(strlen(acctTmp)+1));
|
||||||
}
|
|
||||||
char *path = (char *) malloc(strlen(pathTmp));
|
memcpy(tmp_paths[listNumber], pathTmp, sizeof(char)*(strlen(pathTmp)+1));
|
||||||
char *acct = (char *) malloc(strlen(acctTmp));
|
memcpy(tmp_accts[listNumber], acctTmp, sizeof(char)*(strlen(acctTmp)+1));
|
||||||
path = pathTmp;
|
|
||||||
acct = acctTmp;
|
|
||||||
tmp_paths[listNumber] = (char *) malloc(sizeof(char)*(strlen(path)));
|
|
||||||
memcpy(tmp_paths[listNumber], path, sizeof(char)*(strlen(path)));
|
|
||||||
tmp_accts[listNumber] = (char *) malloc(sizeof(char)*(strlen(acct)));
|
|
||||||
memcpy(tmp_accts[listNumber], acct, sizeof(char)*(strlen(acct)));
|
|
||||||
listNumber = listNumber + 1;
|
listNumber = listNumber + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*paths = (char **) realloc(tmp_paths, listNumber);
|
*paths = (char **) realloc(tmp_paths, (int)sizeof(char *)*listNumber);
|
||||||
*accts = (char **) realloc(tmp_accts, listNumber);
|
*accts = (char **) realloc(tmp_accts, (int)sizeof(char *)*listNumber);
|
||||||
|
|
||||||
*list_l = listNumber;
|
*list_l = listNumber;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user