Using Shell Injection to Add a File Extension
How I can add the file extension inside of the shell injection without having to use ruby to add the extension? I'd prefer to keep the solution inside of the backticks.
Code:
def self.md5_sum(uri) (Note the file extension could end in ".png") Code:
`md5 -s $(basename #{uri}) | cut -d"=" -f2 | \ |
it is 'echo' or 'printf' in shell
Don't forget though that calling shell instead using the built-in tools is: * very slow * can be insecure * makes the program platform-dependent * a sure sign of laziness |
I learned this after running some tests on this. I'm more concerned about security than anything, so I went with:
Code:
Digest::MD5.hexdigest(File.basename(uri)) + File.extname(uri) |
now you are not just changing any png format images and renaming them to jpg
that will not work out well a jpg format is not a png format |
Correct, that was just an attempt to solve the issue. Ultimately, it's better to use the standard tool provided by Ruby which was my answer after @NevemTeve above.
|
All times are GMT -5. The time now is 04:17 PM. |