Wednesday, July 06, 2011

Debug Memory Corruptions in Linux,,,,,,

Was first time, trying to debug a memory corruption(in Linux) happening in the code written by me :).


From some time, have been seeing it happening in some scenarios, but was continuing with the development as I was not in mood then to debug it.


But, certainly, it would never get fixed by itself, so had started trying to debug the issue.


Used various means, reviewed most of the code and found some places which might cause a corruption. But none fixed the issue I was seeing.


Then, used Valgrind, it provided very useful insights, and fixed some more places where it showed possible trouble. But, still the original issue was still there.


Finally, today found this wonderful compilation option provided by gcc (-fstack-protector-all)
It is basically called "Stack-Smashing Protector(ProPolice)"
This option, when enabled, adds some additional security(checks) to all functions and provides buffer overflow protection.
When ever, inside a function, it sees the buffer overflow, it immediately sends a SIGABRT signal to the process.
So, using gdb, you immediately catch the signal and get the call stack and easily know the function where this overflow is happening and fix it.


Probably, it is not a bad idea to just run the binary with this option enabled atleast once b4 the final release, even if u do not see a crash, just to make sure, it doesn't crash in some particular environments.


Valgrind and -fstack-protector-all are Super :).

Thursday, March 10, 2011

Export/Import puTTY settings across machines.

Was recently checking, how to move all the puTTY settings we have across various machines.

 

It’s very simple, just export and import the following registry keys:

 

HKEY_CURRENT_USER\Software\SimonTatham

 

And FYI, Simon Tatham is the The Man who developed the puTTY and maintaining the same.

 

More interesting information about him and puTTY  can be found here .

 

Have fun,,,,

 

Cheers,

Santhosh

Friday, September 03, 2010

Useful Windows Tips [I've been gathering over a period of time]

I very much enjoy doing the various common tasks on Windows using various shortcuts Microsoft provides.

I've captured some of such important tips in a txt file till now. Just thought will post it in to the blog, so that I can continuously append the tips to it:

I've as such not formatted it much. [May be I'll do later, as of now just a copy paste from txt :)]

================================================

1) Add your own commands to WINDOWS+R commands:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

2) equivalent to cd -
    pushd     [It will store PWD and cd to new dir]
    popd            [to come back to old dir]



3) Without opening outlook, how to open a new mail window:
Windows + Run ==> Type mailto:

there comes the new outlook mail window,,


4) Access Windows clipboard from command line(both read and write) using clip.exe which comes with Windows Server 2003. Same file can be found here clip.zip
  * dir /h | clip – Copy the help manual for DIR command to the clipboard
   *  clip < C:\AUTOEXEC.bat – this will copy all the text from autoexec.bat to your Windows Clipboard.

#unix diff
fc.exe : Compare files

mem: Display memory usage

pause:

#unix history equiv
doskey /history

#search commands in history:
enter starting of command and press F8

#command to get free space
fsutil volume diskfree C:

#cd - of UNIX
pushd .
cd
popd

#cat
type
more

#change IP
conf_ip.bat

#grep
find/findstr

#alias for commands
doskey ct=cleartool

>If you want to start a program (like DOSKEY) or set an environment variable each
>time you open a command prompt:
>
>1. Start Regedit
>2. Go to HKEY_CURRENT_USER\Software\Microsoft\Command Processor
>3. Create a String key called Autorun
>4. Give it the value = c:\autoexec.bat
>5. Multiple commands need to be separated by a double ampersand (&&)


wikipedia windows commands

#for in windows
for %a in (*.*) do cleartool lsvtree -g "%a"

#list of all running processes with full parameters.
WMIC /OUTPUT:C:\ProcessList.txt path win32_process get Caption,Processid,Commandline


#for sleep,,,use the windows resource tool kit sleep.exe..it works
c:\Program Files\Windows Resource Kits\Tools\sleep.exe


#infinite loop in windows
for /l %i in (1,0,2) do

#start miniminsed
start /min

#current date
%date%

#multiple commands at once in windows
(ovpacmd stop
ovpacmd start
.
.
)
Also, & can be used
 command1 & command2
 Execute Command1 and then execute Command2



If you want to print the latest time in command prompt:
time /t (only HH:MM )
echo %time% (more detailed)
================================================


Textpad tips
================================================
General important things, which I will never forget, so only one words for them


- Block Selection
- Sort
- compare files
- clip library
- changing the "File Type" and "Code Set" while Saving As,,
- bookmarking and edit operations on those bookmarked lines,
- Find in files,,


- While finding/replacing in files, you can also pass regular expression to it. It handles
  = "\n", \t"
  = Give ^ in find field and in replace field, it adds the at the begining of all the lines.

  = Give $ in find field and in replace field, it adds the at the ending of all the lines.


================================================


Linux tips
================================================
1) Print one line from a file:
  - sed -n 3p file [Prints 3rd line]
2) Print one column from a file:
  - cut -c5-7 somefile [Prints columns 5 to 7]
================================================

Cheers
Santhosh

Thursday, April 08, 2010

MS Office keyboard shortcuts


Many times, I will be forgetting the shortcuts in MS Office applications.
So, thought of maintaining this as a one place for all shortcuts i like/use:

Hence, dumping it here J

- To increase and decrease indent with MS Office applications.
Increase Indent: Ctrl +t
Decrease Indent: Ctrl +Shift +t

The shortcut for copying formatting is Ctrl+Shift+C and the shortcut for pasting is Ctrl+Shift+V.

Cheers,
Santhosh

Dynamic memory part of Hyper-V R2 SP1

Good to see that Dynamic Memory will be supported by Hyper-V.
 
Currently, once memory is assigned to a VM, independent of its usage by the VM, the complete amount of RAM memory is reserved for the VM’s usage. This is not a good way to handle the much costlier memory.
 
Anyways, Hyper-V team already came up with a solution for it with Dynamic Memory,,
 
And following are some of the nice articles, which give an insight on what it is and the various investigations they’ve done to give the best possible solution to customers,,
 
Thanks to Jeff Woolsey and Ben Armstrong.
 
Cheers,
Santhosh
 

Monday, March 29, 2010

Windows 2003 "server" service not starting(Access denied)

On Windows 2003 servers, if you see following error while trying to start server(lanmanserver) service:
 
Acess is denied.
 
Without the service, file sharing will not work on that machine.
 
Installing the following hotfixes will fix the issue:
 
 
 
Cheers,
Santhosh
 

Thursday, March 18, 2010

how to run a cmd.exe as a local system account user?

 
Strike 1:
I found information online which suggests lauching the CMD.exe using the DOS Task Scheduler AT command.  Here’s a sample command:
AT 12:00 /interactive cmd.exe
I gave it a shot but I received a Vista warning that “due to security enhancements, this task will run at the time excepted but not interactively.”
It turns out that this approach will work for XP, 2000 and Server 2003 but due tosession 0 isolation Interactive services no longer work on Windows Vista and Windows Server 2008.
 
Strike 2:
Another solution suggested creating a secondary Windows Service via the Service Control (sc.exe) which merely launches CMD.exe.
C:\sc create RunCMDAsLSA binpath= "cmd" type=own type=interactC:\sc start RunCMDAsLSA
In this case the service fails to start and results it the following error message:
FAILED 1053: The service did not respond to the start or control request in a timely fashion.
 
Strike 3:
The third suggestion was to launch CMD.exe via a Scheduled Task. Though you may run scheduled tasks under various accounts, I don’t believe the Local System Account is one of them. I’ve tried using the Runas as well, but think I’m running into the same restriction as found when running a scheduled task.
 
Not Out Yet:
Fortunately, I came across this article which demonstrates the use of PSTools fromSysInternals which was acquired by Microsoft in July, 2006. I launched the command line and issued the following statement and suddenly I was running under the Local System Account like magic:
psexec -i -s cmd.exe
PSTools worked great. It’s a lightweight, well-documented set of tools which provided an appropriate solution to my problem.
 
 
Cheers,
Santhosh
 

Thursday, February 11, 2010

The application was unable to start correctly (0xc000007b). Click OK to close the application.


The application was unable to start correctly (0xc000007b). Click OK to close the application.
 






I wasted quite an amount of time figuring out the cause for above error on a newly created Windows 2008 Server core system(x86_64).
Finally found that, following was the cause of the problem:
        - The Application(EXE) needs a dll(say XYZ.dll).
        - On that machine, it was finding a 32-bit dll with same name. The directory where the 64-bit DLL was present was not added to the %PATH%.
        - Normally on most of the machines, it will not load the 32-bit dll and show the following standard error message(This application has failed to start because XYZ.dll was not found)
       




But, on that server core machine, instead of throwing this error message, it was throwing the most confusing Application Error message.
Cheers,
Santhosh

What if a directory named "C:\Program" exists?


Assumption: Windows operating system is installed on C:\
Say, on a windows machine, there is a directory called C:\Program.
- Will it have any effect?
YES.
- What are those?
It may disrupt many of the badly designed applications running on your system. [Even though the mistake is done by the ones who programmed those, as they are currently running on your system, you are the sufferer. Welcome to S/W Industry :) ]
- Is there a simple example to show it?
Here it is:












As u can see above, dir command has got confused with the C:\Program directory.
In similar way, if some Programmer has not used the quotes(") properly, then, that's it, it will behave strangely and may do anything on ur system.
So , best thing is to immediately rename or delete such directory "%SystemDrive%\Program"


As, u can see below, once that troublesome directory is gone, dir is behaving normally again :)

 














Happy Weekend :)
Cheers
Santhosh