svn commit: r356569 - head/lib/libc/locale
Mark Johnston
markj at FreeBSD.org
Thu Jan 9 20:49:27 UTC 2020
Author: markj
Date: Thu Jan 9 20:49:26 2020
New Revision: 356569
URL: https://svnweb.freebsd.org/changeset/base/356569
Log:
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
Modified:
head/lib/libc/locale/collate.c
head/lib/libc/locale/rune.c
Modified: head/lib/libc/locale/collate.c
==============================================================================
--- head/lib/libc/locale/collate.c Thu Jan 9 20:45:01 2020 (r356568)
+++ head/lib/libc/locale/collate.c Thu Jan 9 20:49:26 2020 (r356569)
@@ -109,7 +109,7 @@ __collate_load_tables(const char *encoding)
return (__collate_load_tables_l(encoding, &__xlocale_global_collate));
}
-int
+static int
__collate_load_tables_l(const char *encoding, struct xlocale_collate *table)
{
int i, chains, z;
@@ -147,7 +147,7 @@ __collate_load_tables_l(const char *encoding, struct x
}
map = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
(void) _close(fd);
- if ((TMP = map) == NULL) {
+ if ((TMP = map) == MAP_FAILED) {
return (_LDP_ERROR);
}
@@ -181,6 +181,11 @@ __collate_load_tables_l(const char *encoding, struct x
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->char_pri_table = (void *)TMP;
TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1);
Modified: head/lib/libc/locale/rune.c
==============================================================================
--- head/lib/libc/locale/rune.c Thu Jan 9 20:45:01 2020 (r356568)
+++ head/lib/libc/locale/rune.c Thu Jan 9 20:49:26 2020 (r356569)
@@ -94,7 +94,7 @@ _Read_RuneMagi(const char *fname)
fdata = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
(void) _close(fd);
- if (fdata == NULL) {
+ if (fdata == MAP_FAILED) {
errno = EINVAL;
return (NULL);
}
More information about the svn-src-all
mailing list