View | Details | Raw Unified | Return to bug 172805 | Differences between
and this patch

Collapse All | Expand All

(-)lib/libc/nls/catopen.3 (-3 / +6 lines)
Lines 27-33 Link Here
27
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
.\"
28
.\"
29
.\" $FreeBSD$
29
.\" $FreeBSD$
30
.Dd February 12, 2005
30
.Dd October 17, 2012
31
.Dt CATOPEN 3
31
.Dt CATOPEN 3
32
.Os
32
.Os
33
.Sh NAME
33
.Sh NAME
Lines 132-141 Otherwise, (nl_catd) -1 is returned and Link Here
132
is set to indicate the error.
132
is set to indicate the error.
133
.Sh ERRORS
133
.Sh ERRORS
134
.Bl -tag -width Er
134
.Bl -tag -width Er
135
.It Bq Er EFTYPE
136
The target file is not a formatted message catalog file.
135
.It Bq Er EINVAL
137
.It Bq Er EINVAL
136
Argument
138
Argument
137
.Fa name
139
.Fa name
138
does not point to a valid message catalog, or catalog is corrupt.
140
points to
141
.Dv NULL .
139
.It Bq Er ENAMETOOLONG
142
.It Bq Er ENAMETOOLONG
140
An entire path to the message catalog exceeded 1024 characters.
143
An entire path to the message catalog exceeded 1024 characters.
141
.It Bq Er ENOENT
144
.It Bq Er ENOENT
Lines 154-157 Insufficient memory is available. Link Here
154
The
157
The
155
.Fn catopen
158
.Fn catopen
156
function conforms to
159
function conforms to
157
.St -p1003.1-2001 .
160
.St -p1003.1-2008 .
(-)lib/libc/nls/msgcat.c (-2 / +21 lines)
Lines 119-126 catopen(const char *name, int type) Link Here
119
	char path[PATH_MAX];
119
	char path[PATH_MAX];
120
120
121
	/* sanity checking */
121
	/* sanity checking */
122
	if (name == NULL || *name == '\0')
122
	if (name == NULL)
123
		NLRETERR(EINVAL);
123
		NLRETERR(EINVAL);
124
	if (*name == '\0')
125
		NLRETERR(ENOENT);
124
126
125
	if (strchr(name, '/') != NULL)
127
	if (strchr(name, '/') != NULL)
126
		/* have a pathname */
128
		/* have a pathname */
Lines 367-372 load_msgcat(const char *path, const char *name, const char *lang) Link Here
367
	struct catentry *np;
369
	struct catentry *np;
368
	void *data;
370
	void *data;
369
	int fd;
371
	int fd;
372
	int saved_errno;
370
373
371
	/* path/name will never be NULL here */
374
	/* path/name will never be NULL here */
372
375
Lines 390-395 load_msgcat(const char *path, const char *name, const char *lang) Link Here
390
	}
393
	}
391
394
392
	if (_fstat(fd, &st) != 0) {
395
	if (_fstat(fd, &st) != 0) {
396
		saved_errno = errno;
397
		_close(fd);
398
		SAVEFAIL(name, lang, saved_errno);
399
		NLRETERR(saved_errno);
400
	}
401
402
	/* The file is too small to contain a _NLS_MAGIC. */
403
	if (st.st_size < sizeof(u_int32_t)) {
393
		_close(fd);
404
		_close(fd);
394
		SAVEFAIL(name, lang, EFTYPE);
405
		SAVEFAIL(name, lang, EFTYPE);
395
		NLRETERR(EFTYPE);
406
		NLRETERR(EFTYPE);
Lines 408-414 load_msgcat(const char *path, const char *name, const char *lang) Link Here
408
419
409
	if ((data = mmap(0, (size_t)st.st_size, PROT_READ,
420
	if ((data = mmap(0, (size_t)st.st_size, PROT_READ,
410
	    MAP_FILE|MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) {
421
	    MAP_FILE|MAP_SHARED, fd, (off_t)0)) == MAP_FAILED) {
411
		int saved_errno = errno;
422
		/*
423
		 * mmap(2) sets EINVAL when the filetype is not mappable.
424
		 * By capturing this, we can make sure EINVAL is exported
425
		 * iff the original name argument is NULL.
426
		 */
427
		if (errno == EINVAL)
428
			saved_errno = EFTYPE;
429
		else
430
			saved_errno = errno;
412
		_close(fd);
431
		_close(fd);
413
		SAVEFAIL(name, lang, saved_errno);
432
		SAVEFAIL(name, lang, saved_errno);
414
		NLRETERR(saved_errno);
433
		NLRETERR(saved_errno);

Return to bug 172805