Skip to content

Commit 02e2617

Browse files
committed
changes from feedback
1 parent ab0bc74 commit 02e2617

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
@@ -37,11 +37,9 @@
3737
#include <selinux/selinux.h>
3838
#endif
3939

40-
#ifdef HAVE_SCHED_H
40+
#if defined(HAVE_SCHED_H)
4141
#include <sched.h>
42-
#endif
43-
44-
#ifdef HAVE_SYS_CPUSET_H
42+
#elif defined(HAVE_SYS_CPUSET_H)
4543
#include <sys/cpuset.h>
4644
typedef cpuset_t cpu_set_t;
4745
#endif
@@ -478,21 +476,27 @@ static int fpm_cpuaffinity_set(cpu_set_t *c)
478476

479477
static int fpm_setcpuaffinity(char *cpu_list)
480478
{
481-
char *token, *buf;
479+
char *token, *buf, *ptr;
482480
cpu_set_t c;
483481
int r, cpumax, min, max;
484482

485483
r = -1;
486484
cpumax = fpm_cpumax();
487485

488486
fpm_cpuaffinity_init(&c);
489-
token = php_strtok_r(cpu_list, ",", &buf);
487+
ptr = estrdup(cpu_list);
488+
token = php_strtok_r(ptr, ",", &buf);
490489

491490
while (token) {
492491
char *cpu_listsep;
493492

493+
if (!isdigit(*token)) {
494+
return -1;
495+
}
496+
494497
min = strtol(token, &cpu_listsep, 0);
495-
if (errno || min < 0 || min > cpumax) {
498+
if (errno || (*cpu_listsep != '\0' && *cpu_listsep != '-') || min < 0 || min > cpumax) {
499+
efree(ptr);
496500
return -1;
497501
}
498502
max = min;
@@ -501,19 +505,21 @@ static int fpm_setcpuaffinity(char *cpu_list)
501505
char *err;
502506
max = strtol(cpu_listsep + 1, &err, 0);
503507
if (errno || *err != '\0' || max < min || max > cpumax) {
508+
efree(ptr);
504509
return -1;
505510
}
506511
} else {
512+
efree(ptr);
507513
return -1;
508514
}
509515
}
510516

511517
fpm_cpuaffinity_add(&c, min, max);
512-
513-
token = php_strtok_r(NULL, ";", &buf);
518+
token = php_strtok_r(NULL, ",", &buf);
514519
}
515520

516521
r = fpm_cpuaffinity_set(&c);
522+
efree(ptr);
517523
return r;
518524
}
519525
#endif

0 commit comments

Comments
 (0)