libc: Fix a few bugs in the xlocale collation code.
- Fix checks for mmap() failures. [1] - Set the "map" and "maplen" fields of struct xlocale_collate so that the table destructor actually does something. - Free an already-mapped collation file before loading a new one into the global table. - Harmonize the prototype and definition of __collate_load_tables_l() by adding the "static" qualifier to the latter. PR: 243195 Reported by: cem [1] Reviewed by: cem, yuripv MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D23109
This commit is contained in:
parent
4c8095b1d5
commit
57e642365b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356569
@ -109,7 +109,7 @@ __collate_load_tables(const char *encoding)
|
|||||||
return (__collate_load_tables_l(encoding, &__xlocale_global_collate));
|
return (__collate_load_tables_l(encoding, &__xlocale_global_collate));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
__collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
|
__collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
|
||||||
{
|
{
|
||||||
int i, chains, z;
|
int i, chains, z;
|
||||||
@ -147,7 +147,7 @@ __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
|
|||||||
}
|
}
|
||||||
map = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
map = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
(void) _close(fd);
|
(void) _close(fd);
|
||||||
if ((TMP = map) == NULL) {
|
if ((TMP = map) == MAP_FAILED) {
|
||||||
return (_LDP_ERROR);
|
return (_LDP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +181,11 @@ __collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
|
|||||||
return (_LDP_ERROR);
|
return (_LDP_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (table->map && (table->maplen > 0)) {
|
||||||
|
(void) munmap(table->map, table->maplen);
|
||||||
|
}
|
||||||
|
table->map = map;
|
||||||
|
table->maplen = sbuf.st_size;
|
||||||
table->info = info;
|
table->info = info;
|
||||||
table->char_pri_table = (void *)TMP;
|
table->char_pri_table = (void *)TMP;
|
||||||
TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1);
|
TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1);
|
||||||
|
@ -94,7 +94,7 @@ _Read_RuneMagi(const char *fname)
|
|||||||
|
|
||||||
fdata = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
fdata = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
(void) _close(fd);
|
(void) _close(fd);
|
||||||
if (fdata == NULL) {
|
if (fdata == MAP_FAILED) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user