diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-09-21 16:35:30 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-09-21 16:35:30 +0200 |
commit | d1d0a0d42dae36048b36860cfe43c086cfa4e321 (patch) | |
tree | f165ec256c561ab6b4f0c5bd19295e913e3bb791 | |
parent | 0a7a6229dd130cf7abd4f5ddc462fe21b18d0714 (diff) | |
download | dns-d1d0a0d42dae36048b36860cfe43c086cfa4e321.tar.gz |
Fix wrong length in DB Query
-rw-r--r-- | src/zonefile.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/zonefile.c b/src/zonefile.c index 9104ad5..ae32c6d 100644 --- a/src/zonefile.c +++ b/src/zonefile.c @@ -80,19 +80,20 @@ int zonefile_parse_line(database_t *_database, char *_line) { db_entry = malloc((unsigned)data_len + 6); if ( !db_entry ) goto err; + memset(db_entry, 0, (unsigned)data_len + 6); DEBUG("Found %s record at %s", parts[3], parts[0]); *((uint32_t*)db_entry) = ttl; - *((uint16_t*)db_entry+4) = (uint16_t) data_len; + *((uint16_t*)(db_entry+4)) = (uint16_t) data_len; strncpy(db_entry+6, data, (unsigned)data_len); - /* Error Here */ - DEBUG("LEN: %u, %i", *( (uint16_t*)(db_entry + 4) ), data_len); - /* This breaks abstraction boundries! */ - ret = tree_insert( &_database->zone[class-1][type-1], qname, db_entry ); - + if ( tree_insert( &_database->zone[class-1][type-1], qname, db_entry ) ) { + LOGPRINTF(_LOG_ERROR, "Failed to insert in database. Does this record already exist?"); + free(db_entry); + goto err; + } free(data); return 0; |