Skip to content

Commit

Permalink
Merge pull request from GHSA-g9w7-h2f5-5vp2
Browse files Browse the repository at this point in the history
Fix a double free in the List functions
  • Loading branch information
guillaumerose authored Jul 16, 2019
2 parents 680ca48 + 87c80bf commit 1c9f7ed
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 7 deletions.
1 change: 0 additions & 1 deletion osxkeychain/osxkeychain_darwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,4 @@ void freeListData(char *** data, unsigned int length) {
for(int i=0; i<length; i++) {
free((*data)[i]);
}
free(*data);
}
5 changes: 2 additions & 3 deletions osxkeychain/osxkeychain_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func (h Osxkeychain) List() (map[string]string, error) {
defer C.free(unsafe.Pointer(acctsC))
var listLenC C.uint
errMsg := C.keychain_list(credsLabelC, &pathsC, &acctsC, &listLenC)
defer C.freeListData(&pathsC, listLenC)
defer C.freeListData(&acctsC, listLenC)
if errMsg != nil {
defer C.free(unsafe.Pointer(errMsg))
goMsg := C.GoString(errMsg)
Expand All @@ -119,9 +121,6 @@ func (h Osxkeychain) List() (map[string]string, error) {
return nil, errors.New(goMsg)
}

defer C.freeListData(&pathsC, listLenC)
defer C.freeListData(&acctsC, listLenC)

var listLen int
listLen = int(listLenC)
pathTmp := (*[1 << 30]*C.char)(unsafe.Pointer(pathsC))[:listLen:listLen]
Expand Down
1 change: 0 additions & 1 deletion secretservice/secretservice_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,4 @@ void freeListData(char *** data, unsigned int length) {
for(i=0; i<length; i++) {
free((*data)[i]);
}
free(*data);
}
4 changes: 2 additions & 2 deletions secretservice/secretservice_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func (h Secretservice) List() (map[string]string, error) {
defer C.free(unsafe.Pointer(acctsC))
var listLenC C.uint
err := C.list(credsLabelC, &pathsC, &acctsC, &listLenC)
defer C.freeListData(&pathsC, listLenC)
defer C.freeListData(&acctsC, listLenC)
if err != nil {
defer C.g_error_free(err)
return nil, errors.New("Error from list function in secretservice_linux.c likely due to error in secretservice library")
}
defer C.freeListData(&pathsC, listLenC)
defer C.freeListData(&acctsC, listLenC)

resp := make(map[string]string)

Expand Down

0 comments on commit 1c9f7ed

Please sign in to comment.