Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/vt/vt_font.c
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
/* Some limits to prevent abnormal fonts from being loaded. */ | /* Some limits to prevent abnormal fonts from being loaded. */ | ||||
#define VTFONT_MAXMAPPINGS 65536 | #define VTFONT_MAXMAPPINGS 65536 | ||||
#define VTFONT_MAXGLYPHS 131072 | #define VTFONT_MAXGLYPHS 131072 | ||||
#define VTFONT_MAXGLYPHSIZE 2097152 | #define VTFONT_MAXGLYPHSIZE 2097152 | ||||
#define VTFONT_MAXDIMENSION 128 | #define VTFONT_MAXDIMENSION 128 | ||||
static uint16_t | static uint16_t | ||||
vtfont_bisearch(const struct vt_font_map *map, unsigned int len, uint32_t src) | vtfont_bisearch(const vfnt_map_t *map, unsigned int len, uint32_t src) | ||||
{ | { | ||||
int min, mid, max; | int min, mid, max; | ||||
min = 0; | min = 0; | ||||
max = len - 1; | max = len - 1; | ||||
/* Empty font map. */ | /* Empty font map. */ | ||||
if (len == 0) | if (len == 0) | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | if (refcount_release(&vf->vf_refcount)) { | ||||
for (i = 0; i < VFNT_MAPS; i++) | for (i = 0; i < VFNT_MAPS; i++) | ||||
free(vf->vf_map[i], M_VTFONT); | free(vf->vf_map[i], M_VTFONT); | ||||
free(vf->vf_bytes, M_VTFONT); | free(vf->vf_bytes, M_VTFONT); | ||||
free(vf, M_VTFONT); | free(vf, M_VTFONT); | ||||
} | } | ||||
} | } | ||||
static int | static int | ||||
vtfont_validate_map(struct vt_font_map *vfm, unsigned int length, | vtfont_validate_map(vfnt_map_t *vfm, unsigned int length, | ||||
unsigned int glyph_count) | unsigned int glyph_count) | ||||
{ | { | ||||
unsigned int i, last = 0; | unsigned int i, last = 0; | ||||
for (i = 0; i < length; i++) { | for (i = 0; i < length; i++) { | ||||
/* Not ordered. */ | /* Not ordered. */ | ||||
if (i > 0 && vfm[i].vfm_src <= last) | if (i > 0 && vfm[i].vfm_src <= last) | ||||
return (EINVAL); | return (EINVAL); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | vtfont_load(vfnt_t *f, struct vt_font **ret) | ||||
vf->vf_width = f->width; | vf->vf_width = f->width; | ||||
vf->vf_refcount = 1; | vf->vf_refcount = 1; | ||||
/* Allocate, copy in, and validate mappings. */ | /* Allocate, copy in, and validate mappings. */ | ||||
for (i = 0; i < VFNT_MAPS; i++) { | for (i = 0; i < VFNT_MAPS; i++) { | ||||
vf->vf_map_count[i] = f->map_count[i]; | vf->vf_map_count[i] = f->map_count[i]; | ||||
if (f->map_count[i] == 0) | if (f->map_count[i] == 0) | ||||
continue; | continue; | ||||
mapsize = f->map_count[i] * sizeof(struct vt_font_map); | mapsize = f->map_count[i] * sizeof(vfnt_map_t); | ||||
vf->vf_map[i] = malloc(mapsize, M_VTFONT, M_WAITOK); | vf->vf_map[i] = malloc(mapsize, M_VTFONT, M_WAITOK); | ||||
error = copyin(f->map[i], vf->vf_map[i], mapsize); | error = copyin(f->map[i], vf->vf_map[i], mapsize); | ||||
if (error) | if (error) | ||||
goto bad; | goto bad; | ||||
error = vtfont_validate_map(vf->vf_map[i], vf->vf_map_count[i], | error = vtfont_validate_map(vf->vf_map[i], vf->vf_map_count[i], | ||||
f->glyph_count); | f->glyph_count); | ||||
if (error) | if (error) | ||||
goto bad; | goto bad; | ||||
Show All 14 Lines |