String sanitizing

T

Travis Warlick

I have implemented a sanitize! method into the String class to
properly erase Strings from memory (example usage: clearing a password
from memory), but I want to make sure that what I'm doing is actually
doing what I think it is.

Basically, is this code going to leave _anything_ lying around in
memory because of any undocumented/strange behavior or side effects of
the []= method?

class String
def sanitize!
for i in 0...self.length
self = 0
end
self.delete!("\000")
end
end

Also, feel free to recommend any "better" ways to do this.

--
Travis

"You get it, hm? But it's not your head
that needs to understand!"
-- Hatsumi O'Sensei
 
D

David A. Black

Hi --

I have implemented a sanitize! method into the String class to properly erase
Strings from memory (example usage: clearing a password from memory), but I
want to make sure that what I'm doing is actually doing what I think it is.

Basically, is this code going to leave _anything_ lying around in memory
because of any undocumented/strange behavior or side effects of the []=
method?

class String
def sanitize!
for i in 0...self.length
self = 0
end
self.delete!("\000")
end
end

Also, feel free to recommend any "better" ways to do this.


Yes: don't give it an unpaired !-terminated name :)

http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist

I know that's not an answer to your question, but I'm not sure about
the memory handling, especially as it might work in different Ruby
implementations and/or versions.


David

--
Rails training from David A. Black and Ruby Power and Light:
Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
Advancing with Rails January 19-22 Fort Lauderdale, FL *
* Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,654
Latest member
LannySinge

Latest Threads

Top