LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 12-26-2015, 02:40 AM   #1
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Rep: Reputation: 81
Overwrite bash string variable


Code:
read -p 'Password: ' -s password
How do I overwrite the $password variable in memory?

Is it possible to memset it?
 
Old 12-26-2015, 06:10 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You want to assign a different value to a variable? This is done as follows:
Code:
password=whatevervalueyouwanttosetitto
This includes the empty string:
Code:
password=""
You can also unset the variable:
Code:
unset password
When unset, attempting to access $password will result in an error.

Or do you need to do something else?
 
Old 12-26-2015, 07:18 AM   #3
Soderlund
Member
 
Registered: Aug 2012
Posts: 185

Original Poster
Rep: Reputation: 81
When you set a variable, it is stored in dynamically allocated memory (RAM or swap). I need to overwrite the bytes that the string used in memory. When you assign it another value or unset it, it is probably just freed, i.e. the memory is marked as "writable" but the string may still be there.
 
Old 12-26-2015, 07:59 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Nope. Not going to happen. Every string is replicated during assignment, and the pre-existing string deallocated.

There is no "overwrite".

If you are actually doing secure coding, use C instead, you have the control over any storage used.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how can I create a string variable in bash in a specific format in bash mia_tech Linux - General 7 05-29-2014 11:34 AM
[SOLVED] BASH - resolve string with value of variable name leeclements Programming 9 01-12-2012 08:59 AM
[SOLVED] Bash concatenating string to variable abercrombieande Programming 4 01-19-2011 07:04 AM
[SOLVED] BASH: if Variable -eq String not working worm5252 Programming 2 01-24-2010 03:07 PM
Bash variable string expansion Reginald0 Linux - Software 5 02-13-2007 10:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 02:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration