Skip to content

Commit 40d75e2

Browse files
omusjrevels
authored andcommitted
Missed shred calls
1 parent 1ad1b33 commit 40d75e2

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

stdlib/LibGit2/src/types.jl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,14 @@ mutable struct UserPasswordCredential <: AbstractCredential
12081208
UserPasswordCredential(prompt_if_incorrect::Bool) = UserPasswordCredential("","",prompt_if_incorrect)
12091209
end
12101210

1211+
function Base.setproperty!(cred::UserPasswordCredential, name::Symbol, value)
1212+
if name == :pass
1213+
field = getfield(cred, name)
1214+
Base.shred!(field)
1215+
end
1216+
setfield!(cred, name, convert(fieldtype(typeof(cred), name), value))
1217+
end
1218+
12111219
function Base.shred!(cred::UserPasswordCredential)
12121220
cred.user = ""
12131221
Base.shred!(cred.pass)
@@ -1246,6 +1254,15 @@ mutable struct SSHCredential <: AbstractCredential
12461254
SSHCredential(prompt_if_incorrect::Bool) = SSHCredential("","","","",prompt_if_incorrect)
12471255
end
12481256

1257+
function Base.setproperty!(cred::SSHCredential, name::Symbol, value)
1258+
if name == :pass
1259+
field = getfield(cred, name)
1260+
Base.shred!(field)
1261+
end
1262+
setfield!(cred, name, convert(fieldtype(typeof(cred), name), value))
1263+
end
1264+
1265+
12491266
function Base.shred!(cred::SSHCredential)
12501267
cred.user = ""
12511268
Base.shred!(cred.pass)
@@ -1378,7 +1395,7 @@ should be destroyed. Should only be set to `false` during testing.
13781395
"""
13791396
function approve(p::CredentialPayload; shred::Bool=true)
13801397
cred = p.credential
1381-
cred === nothing && return # No credentials were used
1398+
cred === nothing && return # No credential was used
13821399

13831400
if p.cache !== nothing
13841401
approve(p.cache, cred, p.url)
@@ -1388,7 +1405,10 @@ function approve(p::CredentialPayload; shred::Bool=true)
13881405
approve(p.config, cred, p.url)
13891406
end
13901407

1391-
shred && Base.shred!(cred)
1408+
if shred
1409+
Base.shred!(cred)
1410+
p.credential = nothing
1411+
end
13921412
nothing
13931413
end
13941414

@@ -1403,17 +1423,19 @@ should be destroyed. Should only be set to `false` during testing.
14031423
"""
14041424
function reject(p::CredentialPayload; shred::Bool=true)
14051425
cred = p.credential
1406-
cred === nothing && return # No credentials were used
1426+
cred === nothing && return # No credential was used
14071427

14081428
if p.cache !== nothing
14091429
reject(p.cache, cred, p.url)
1410-
shred = false # Avoid wiping `cred` as this would also wipe the cached copy
14111430
end
14121431
if p.allow_git_helpers
14131432
reject(p.config, cred, p.url)
14141433
end
14151434

1416-
shred && Base.shred!(cred)
1435+
if shred
1436+
Base.shred!(cred)
1437+
p.credential = nothing
1438+
end
14171439
nothing
14181440
end
14191441

0 commit comments

Comments
 (0)