Skip to content

Commit 4c04aec

Browse files
committed
changes from feedback
1 parent 21acaa8 commit 4c04aec

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

sapi/fpm/fpm/fpm_unix.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
#include <selinux/selinux.h>
3737
#endif
3838

39-
#ifdef HAVE_SCHED_H
39+
#if defined(HAVE_SCHED_H)
4040
#include <sched.h>
41-
#endif
42-
43-
#ifdef HAVE_SYS_CPUSET_H
41+
#elif defined(HAVE_SYS_CPUSET_H)
4442
#include <sys/cpuset.h>
4543
typedef cpuset_t cpu_set_t;
4644
#endif
@@ -449,21 +447,27 @@ static int fpm_cpuaffinity_set(cpu_set_t *c)
449447

450448
static int fpm_setcpuaffinity(char *cpu_list)
451449
{
452-
char *token, *buf;
450+
char *token, *buf, *ptr;
453451
cpu_set_t c;
454452
int r, cpumax, min, max;
455453

456454
r = -1;
457455
cpumax = fpm_cpumax();
458456

459457
fpm_cpuaffinity_init(&c);
460-
token = php_strtok_r(cpu_list, ",", &buf);
458+
ptr = estrdup(cpu_list);
459+
token = php_strtok_r(ptr, ",", &buf);
461460

462461
while (token) {
463462
char *cpu_listsep;
464463

464+
if (!isdigit(*token)) {
465+
return -1;
466+
}
467+
465468
min = strtol(token, &cpu_listsep, 0);
466-
if (errno || min < 0 || min > cpumax) {
469+
if (errno || (*cpu_listsep != '\0' && *cpu_listsep != '-') || min < 0 || min > cpumax) {
470+
efree(ptr);
467471
return -1;
468472
}
469473
max = min;
@@ -472,19 +476,21 @@ static int fpm_setcpuaffinity(char *cpu_list)
472476
char *err;
473477
max = strtol(cpu_listsep + 1, &err, 0);
474478
if (errno || *err != '\0' || max < min || max > cpumax) {
479+
efree(ptr);
475480
return -1;
476481
}
477482
} else {
483+
efree(ptr);
478484
return -1;
479485
}
480486
}
481487

482488
fpm_cpuaffinity_add(&c, min, max);
483-
484-
token = php_strtok_r(NULL, ";", &buf);
489+
token = php_strtok_r(NULL, ",", &buf);
485490
}
486491

487492
r = fpm_cpuaffinity_set(&c);
493+
efree(ptr);
488494
return r;
489495
}
490496
#endif

0 commit comments

Comments
 (0)