background image
<< NULL dereferencing | Race Condition >>

Synchronization Errors

<< NULL dereferencing | Race Condition >>
s t r u c t n o d e {
c h a r * ch ;
};
c h a r * foo ( s t r u c t n o de nn ){
r e t u r n ( nn . ch );
}
m a i n (){
s t r u c t n o d e n ; c h a r * ff ;
n . ch =( c h a r *) m a l l o c ( 1 ) ;
*( n . ch ) = 1 0 0 ;
ff = f ( n );
/* H e r e ff has an a c c e s s to s t r u c t u r e v a r i a b l e */
}
Do not use simple structures when fair amount of security is needed. Or take care that internal
data is not exposed to external resources.
2.2
Aliases
[16]
When there is unexpected aliasing between parameters, return values, and global variables, errors
may be inevitable. Aliasing problems sometimes lead to deallocation errors. Static analysis of all
feasible paths in the program can detect possible aliases.
2.2.1
Need of Unique addresses
(frequent, major) [16]
Aliasing creates many problems among them is violation of unique addresses when we expect dif-
ferent addresses. For example in the string concatenation function, we expect source and destination
addresses to be different.
s t r c a t ( src , d e s t n );
/* In a b o v e f u n c t i o n , if src is a l i a s e d to destn ,
* t h e n we may get a r u n t i m e e r r o r */
To avoid this, keep a check on the parameters before using them. This is more needed when the
function can cause a dangerous side-effect. Be cautious when dealing with functions which expect
parameters to be in certain format.
2.3
Synchronization Errors
[10] [25]
In a parallel program, where there are multiple threads which are accessing some common re-
sources, there is a great chance of causing synchronization problems. There should be some means
of controlling the execution of such concurrent threads and even more when there is a shared data.
These errors are very difficult to find as they don't manifest easily, but are low probability events
causing serious damages to system. This type of errors are generally discovered late in the develop-
ment process. In general, there are three categories of synchronization errors and each of them may
occur under different circumstances.
1. Deadlocks
2. Race conditions
3. Live lock
4