Skip to content

Commit

Permalink
fix tainted int loop bound issue
Browse files Browse the repository at this point in the history
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
  • Loading branch information
2xsec authored and Christian Brauner committed Aug 12, 2018
1 parent 4e194ce commit 14c1904
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/lxc/caps.c
Expand Up @@ -310,7 +310,7 @@ int lxc_caps_init(void)
return 0;
}

static int _real_caps_last_cap(void)
static long int _real_caps_last_cap(void)
{
int fd, result = -1;

Expand Down Expand Up @@ -354,10 +354,13 @@ static int _real_caps_last_cap(void)

int lxc_caps_last_cap(void)
{
static int last_cap = -1;
static long int last_cap = -1;

if (last_cap < 0)
if (last_cap < 0) {
last_cap = _real_caps_last_cap();
if (last_cap < 0 || last_cap > INT_MAX)
last_cap = -1;
}

return last_cap;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -397,7 +397,7 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)

/* Get maximum number of cpus found in possible cpuset. */
maxposs = get_max_cpus(posscpus);
if (maxposs < 0)
if (maxposs < 0 || maxposs >= INT_MAX - 1)
goto on_error;

if (!file_exists(__ISOL_CPUS)) {
Expand Down Expand Up @@ -442,7 +442,7 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)

/* Get maximum number of cpus found in isolated cpuset. */
maxisol = get_max_cpus(isolcpus);
if (maxisol < 0)
if (maxisol < 0 || maxisol >= INT_MAX - 1)
goto on_error;

if (maxposs < maxisol)
Expand Down
4 changes: 2 additions & 2 deletions src/lxc/pam/pam_cgfs.c
Expand Up @@ -1806,7 +1806,7 @@ static bool cg_filter_and_set_cpus(char *path, bool am_initialized)

/* Get maximum number of cpus found in possible cpuset. */
maxposs = cg_get_max_cpus(posscpus);
if (maxposs < 0)
if (maxposs < 0 || maxposs >= INT_MAX - 1)
goto on_error;

if (!file_exists(__ISOL_CPUS)) {
Expand Down Expand Up @@ -1856,7 +1856,7 @@ static bool cg_filter_and_set_cpus(char *path, bool am_initialized)

/* Get maximum number of cpus found in isolated cpuset. */
maxisol = cg_get_max_cpus(isolcpus);
if (maxisol < 0)
if (maxisol < 0 || maxisol >= INT_MAX - 1)
goto on_error;

if (maxposs < maxisol)
Expand Down

0 comments on commit 14c1904

Please sign in to comment.