diff options
author | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2013-05-29 17:24:32 -0700 |
---|---|---|
committer | Luis R. Rodriguez <mcgrof@do-not-panic.com> | 2013-05-29 17:24:32 -0700 |
commit | c2a7392a0696e0dc982bbc2a7f0e4641e0112106 (patch) | |
tree | 9c3f70f4f887a16fb40851fb73b68c036afb67d1 | |
parent | f48dc74c3657e5564895d23adac35433b9898ff2 (diff) | |
download | crda-c2a7392a0696e0dc982bbc2a7f0e4641e0112106.tar.gz |
crda: explicitly use close() and munmap() on reglib_get_rd_alpha2()
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
-rw-r--r-- | reglib.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -262,33 +262,37 @@ reglib_get_rd_idx(unsigned int idx, 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, @@ -296,14 +300,17 @@ reglib_get_rd_idx(unsigned int idx, const char *file) header->reg_country_ptr); if (idx >= num_countries) - return NULL; + goto out; country = countries + idx; rd = country2rd(db, dblen, country); if (!rd) - return NULL; + goto out; +out: + close(fd); + munmap(db, dblen); return rd; } |