Print this page
locale stuff should use libc safe lmalloc.  Other fixes from tests.


  27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32  * SUCH DAMAGE.
  33  */
  34 
  35 #include "lint.h"
  36 #include "file64.h"
  37 #include <errno.h>
  38 #include <stdio.h>
  39 #include <string.h>
  40 #include <stdlib.h>
  41 #include <sys/types.h>
  42 #include <sys/stat.h>
  43 #include <sys/mman.h>
  44 #include <fcntl.h>
  45 #include <unistd.h>
  46 

  47 #include "runetype.h"
  48 #include "runefile.h"
  49 
  50 _RuneLocale *
  51 _Read_RuneMagi(const char *fname)
  52 {
  53         char *fdata, *data;
  54         void *lastp;
  55         _FileRuneLocale *frl;
  56         _RuneLocale *rl;
  57         _FileRuneEntry *frr;
  58         _RuneEntry *rr;
  59         struct stat sb;
  60         int x, saverr;
  61         void *variable;
  62         _FileRuneEntry *runetype_ext_ranges;
  63         _FileRuneEntry *maplower_ext_ranges;
  64         _FileRuneEntry *mapupper_ext_ranges;
  65         int runetype_ext_len = 0;
  66         int fd;


 122                 uint32_t *types;
 123 
 124                 if (frr[x].map == 0) {
 125                         int len = frr[x].max - frr[x].min + 1;
 126                         types = variable;
 127                         variable = types + len;
 128                         runetype_ext_len += len;
 129                         if (variable > lastp) {
 130                                 goto invalid;
 131                         }
 132                 }
 133         }
 134 
 135         if ((char *)variable + frl->variable_len > (char *)lastp) {
 136                 goto invalid;
 137         }
 138 
 139         /*
 140          * Convert from disk format to host format.
 141          */
 142         data = malloc(sizeof (_RuneLocale) +
 143             (frl->runetype_ext_nranges + frl->maplower_ext_nranges +
 144             frl->mapupper_ext_nranges) * sizeof (_RuneEntry) +
 145             runetype_ext_len * sizeof (*rr->__types) +
 146             frl->variable_len);
 147         if (data == NULL) {
 148                 saverr = errno;
 149                 (void) munmap(fdata, sb.st_size);
 150                 errno = saverr;
 151                 return (NULL);
 152         }
 153 
 154         rl = (_RuneLocale *)(void *)data;
 155         rl->__variable = rl + 1;
 156 
 157         (void) memcpy(rl->__magic, _RUNE_MAGIC_1, sizeof (rl->__magic));
 158         (void) memcpy(rl->__encoding, frl->encoding, sizeof (rl->__encoding));
 159 
 160         rl->__variable_len = frl->variable_len;
 161         rl->__runetype_ext.__nranges = frl->runetype_ext_nranges;
 162         rl->__maplower_ext.__nranges = frl->maplower_ext_nranges;




  27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32  * SUCH DAMAGE.
  33  */
  34 
  35 #include "lint.h"
  36 #include "file64.h"
  37 #include <errno.h>
  38 #include <stdio.h>
  39 #include <string.h>
  40 #include <stdlib.h>
  41 #include <sys/types.h>
  42 #include <sys/stat.h>
  43 #include <sys/mman.h>
  44 #include <fcntl.h>
  45 #include <unistd.h>
  46 
  47 #include "libc.h"
  48 #include "runetype.h"
  49 #include "runefile.h"
  50 
  51 _RuneLocale *
  52 _Read_RuneMagi(const char *fname)
  53 {
  54         char *fdata, *data;
  55         void *lastp;
  56         _FileRuneLocale *frl;
  57         _RuneLocale *rl;
  58         _FileRuneEntry *frr;
  59         _RuneEntry *rr;
  60         struct stat sb;
  61         int x, saverr;
  62         void *variable;
  63         _FileRuneEntry *runetype_ext_ranges;
  64         _FileRuneEntry *maplower_ext_ranges;
  65         _FileRuneEntry *mapupper_ext_ranges;
  66         int runetype_ext_len = 0;
  67         int fd;


 123                 uint32_t *types;
 124 
 125                 if (frr[x].map == 0) {
 126                         int len = frr[x].max - frr[x].min + 1;
 127                         types = variable;
 128                         variable = types + len;
 129                         runetype_ext_len += len;
 130                         if (variable > lastp) {
 131                                 goto invalid;
 132                         }
 133                 }
 134         }
 135 
 136         if ((char *)variable + frl->variable_len > (char *)lastp) {
 137                 goto invalid;
 138         }
 139 
 140         /*
 141          * Convert from disk format to host format.
 142          */
 143         data = libc_malloc(sizeof (_RuneLocale) +
 144             (frl->runetype_ext_nranges + frl->maplower_ext_nranges +
 145             frl->mapupper_ext_nranges) * sizeof (_RuneEntry) +
 146             runetype_ext_len * sizeof (*rr->__types) +
 147             frl->variable_len);
 148         if (data == NULL) {
 149                 saverr = errno;
 150                 (void) munmap(fdata, sb.st_size);
 151                 errno = saverr;
 152                 return (NULL);
 153         }
 154 
 155         rl = (_RuneLocale *)(void *)data;
 156         rl->__variable = rl + 1;
 157 
 158         (void) memcpy(rl->__magic, _RUNE_MAGIC_1, sizeof (rl->__magic));
 159         (void) memcpy(rl->__encoding, frl->encoding, sizeof (rl->__encoding));
 160 
 161         rl->__variable_len = frl->variable_len;
 162         rl->__runetype_ext.__nranges = frl->runetype_ext_nranges;
 163         rl->__maplower_ext.__nranges = frl->maplower_ext_nranges;