aboutsummaryrefslogtreecommitdiff
blob: 60c869f65a8ccce535888cd025792424bd2d8f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * opendir() pre-check.
 *
 * Copyright 1999-2016 Gentoo Foundation
 * Licensed under the GPL-2
 */

bool sb_opendir_pre_check(const char *func, const char *name)
{
	/* If length of name is larger than PATH_MAX, we would mess it up
	 * before it reaches the open syscall, which would cleanly error out
	 * via sandbox as well (actually with much smaller lengths than even
	 * PATH_MAX).
	 * So error out early in this case, in order to avoid an abort in
	 * check_syscall later on, which gets ran for opendir, despite it not
	 * being a syscall.
	 */
	if (strnlen(name, PATH_MAX) == PATH_MAX) {
		errno = ENAMETOOLONG;
		sb_debug_dyn("EARLY FAIL: %s(%s): %s\n",
			func, name, strerror(errno));
		return false;
	}

	return true;
}