Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double free when using libxml2 as regex engine #117

Closed
shmuelhazan opened this issue Jun 30, 2020 · 3 comments
Closed

Double free when using libxml2 as regex engine #117

shmuelhazan opened this issue Jun 30, 2020 · 3 comments
Labels

Comments

@shmuelhazan
Copy link
Contributor

shmuelhazan commented Jun 30, 2020

Steps to reproduce

  • Set regex engine to libxml2
  • Use the attached main.yang
  • Run set ips addresses 192.168.0.0

Expected results:

  • command succeed

Actual results:

  • double free (crash):
free(): double free detected in tcache 2
Aborted (core dumped)

main module for example:

module clixon-core {
	prefix "core";
	yang-version 1.1;
	description
	"core functionality of datastore.";
    
	/* yang model example. */
	grouping ip {
		description "ip";
		leaf addr{
			type string {
			      pattern '^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|'        +
              '25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4]'  +
              '[0-9]|25[0-5])$';
			}
		}
	}
	
	/* yang container example. */
	container ips {
		config true;
		description "ip";
		list addresses {
			uses ip;
			key "addr";
			description "list of ips";
		}
	}
}
@shmuelhazan
Copy link
Contributor Author

NOTE: it is possible that this is an issue on libxml2 and not on clixon.

@olofhagsand olofhagsand added the bug label Jul 2, 2020
@olofhagsand
Copy link
Member

Yes I can confirm. here is valgrind stacktrace.

==27620== Command: clixon_cli -f /var/tmp/./test_pattern.sh/pattern.xml -1 set c rfc2 AB
==27620== 
==27620== Invalid free() / delete / delete[] / realloc()
==27620==    at 0x4C30D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27620==    by 0x506630C: match_regexp (cligen_regex.c:308)
==27620==    by 0x505C21D: cv_validate (cligen_cv.c:3260)
==27620==    by 0x505CE45: match_variable (cligen_match.c:104)
==27620==    by 0x505CFBB: match_object (cligen_match.c:159)
==27620==    by 0x505D940: match_vec (cligen_match.c:509)
==27620==    by 0x505DC04: match_pattern_terminal (cligen_match.c:612)
==27620==    by 0x505E066: match_pattern_node (cligen_match.c:763)
==27620==    by 0x505E0B9: match_pattern_node (cligen_match.c:771)
==27620==    by 0x505E0B9: match_pattern_node (cligen_match.c:771)
==27620==    by 0x505E2BB: match_pattern (cligen_match.c:857)
==27620==    by 0x505E397: match_pattern_exact (cligen_match.c:907)
==27620==  Address 0x9ce1b20 is 0 bytes inside a block of size 104 free'd
==27620==    at 0x4C30D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27620==    by 0x5066115: cligen_regex_libxml2_free (cligen_regex.c:208)
==27620==    by 0x506621C: cligen_regex_free (cligen_regex.c:266)
==27620==    by 0x5066300: match_regexp (cligen_regex.c:307)
==27620==    by 0x505C21D: cv_validate (cligen_cv.c:3260)
==27620==    by 0x505CE45: match_variable (cligen_match.c:104)
==27620==    by 0x505CFBB: match_object (cligen_match.c:159)
==27620==    by 0x505D940: match_vec (cligen_match.c:509)
==27620==    by 0x505DC04: match_pattern_terminal (cligen_match.c:612)
==27620==    by 0x505E066: match_pattern_node (cligen_match.c:763)
==27620==    by 0x505E0B9: match_pattern_node (cligen_match.c:771)
==27620==    by 0x505E0B9: match_pattern_node (cligen_match.c:771)
==27620==  Block was alloc'd at
==27620==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27620==    by 0x5BE97EE: ??? (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==27620==    by 0x5BEA1E1: xmlRegexpCompile (in /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.4)
==27620==    by 0x5066081: cligen_regex_libxml2_compile (cligen_regex.c:164)
==27620==    by 0x5066172: cligen_regex_compile (cligen_regex.c:231)
==27620==    by 0x506628B: match_regexp (cligen_regex.c:294)
==27620==    by 0x505C21D: cv_validate (cligen_cv.c:3260)
==27620==    by 0x505CE45: match_variable (cligen_match.c:104)
==27620==    by 0x505CFBB: match_object (cligen_match.c:159)
==27620==    by 0x505D940: match_vec (cligen_match.c:509)
==27620==    by 0x505DC04: match_pattern_terminal (cligen_match.c:612)
==27620==    by 0x505E066: match_pattern_node (cligen_match.c:763)
==27620== 

olofhagsand added a commit that referenced this issue Jul 2, 2020
  * added libxml2 support in test_pattern.sh when libxml2 is configured
@olofhagsand
Copy link
Member

@shmuelhazan thanks for reporting, please verify fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants