diff options
author | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2013-05-29 15:25:48 -0700 |
---|---|---|
committer | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2013-05-29 15:25:48 -0700 |
commit | 385be3f8657634c812572c1541b6b0afc246687e (patch) | |
tree | 34a0f390b6d2ef636bca4c49f08fa82fca56afdc | |
parent | 120c2ea6c3ffdebd696a0ab29ac8762e3d181418 (diff) | |
download | crda-385be3f8657634c812572c1541b6b0afc246687e.tar.gz |
crda: explicitly close file descriptor and munmap() on failures
Just do this explicitly.
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
-rw-r--r-- | reglib.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -307,33 +307,37 @@ reglib_get_rd_alpha2(const char *alpha2, const char *file) if (fd < 0) return NULL; - if (fstat(fd, &stat)) + if (fstat(fd, &stat)) { + close(fd); return NULL; + } dblen = stat.st_size; db = mmap(NULL, dblen, PROT_READ, MAP_PRIVATE, fd, 0); - if (db == MAP_FAILED) + if (db == MAP_FAILED) { + close(fd); return NULL; + } header = crda_get_file_ptr(db, dblen, sizeof(*header), 0); if (ntohl(header->magic) != REGDB_MAGIC) - return NULL; + goto out; if (ntohl(header->version) != REGDB_VERSION) - return NULL; + goto out; siglen = ntohl(header->signature_length); /* adjust dblen so later sanity checks don't run into the signature */ dblen -= siglen; if (dblen <= (int)sizeof(*header)) - return NULL; + goto out; /* verify signature */ if (!crda_verify_db_signature(db, dblen, siglen)) - return NULL; + goto out; num_countries = ntohl(header->reg_country_num); countries = crda_get_file_ptr(db, dblen, |