mirror of
				https://git.haproxy.org/git/haproxy.git/
				synced 2025-10-31 00:21:00 +01:00 
			
		
		
		
	The coccinelle test "unchecked-strdup.cocci" detects various cases of unchecked strdup().
		
			
				
	
	
		
			35 lines
		
	
	
		
			413 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			413 B
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| // find calls to strdup
 | |
| @call@
 | |
| expression ptr;
 | |
| position p;
 | |
| @@
 | |
| 
 | |
| ptr@p = strdup(...);
 | |
| 
 | |
| // find ok calls to strdup
 | |
| @ok@
 | |
| expression ptr;
 | |
| position call.p;
 | |
| @@
 | |
| 
 | |
| ptr@p = strdup(...);
 | |
| ... when != ptr
 | |
| (
 | |
|  (ptr == NULL || ...)
 | |
| |
 | |
|  (ptr == 0 || ...)
 | |
| |
 | |
|  (ptr != NULL || ...)
 | |
| |
 | |
|  (ptr != 0 || ...)
 | |
| )
 | |
| 
 | |
| // fix bad calls to strdup
 | |
| @depends on !ok@
 | |
| expression ptr;
 | |
| position call.p;
 | |
| @@
 | |
| 
 | |
| ptr@p = strdup(...);
 | |
| + if (ptr == NULL) return;
 |