37
37
#include <selinux/selinux.h>
38
38
#endif
39
39
40
- #ifdef HAVE_SCHED_H
40
+ #if defined( HAVE_SCHED_H )
41
41
#include <sched.h>
42
- #endif
43
-
44
- #ifdef HAVE_SYS_CPUSET_H
42
+ #elif defined(HAVE_SYS_CPUSET_H )
45
43
#include <sys/cpuset.h>
46
44
typedef cpuset_t cpu_set_t ;
47
45
#endif
@@ -478,21 +476,27 @@ static int fpm_cpuaffinity_set(cpu_set_t *c)
478
476
479
477
static int fpm_setcpuaffinity (char * cpu_list )
480
478
{
481
- char * token , * buf ;
479
+ char * token , * buf , * ptr ;
482
480
cpu_set_t c ;
483
481
int r , cpumax , min , max ;
484
482
485
483
r = -1 ;
486
484
cpumax = fpm_cpumax ();
487
485
488
486
fpm_cpuaffinity_init (& c );
489
- token = php_strtok_r (cpu_list , "," , & buf );
487
+ ptr = estrdup (cpu_list );
488
+ token = php_strtok_r (ptr , "," , & buf );
490
489
491
490
while (token ) {
492
491
char * cpu_listsep ;
493
492
493
+ if (!isdigit (* token )) {
494
+ return -1 ;
495
+ }
496
+
494
497
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 );
496
500
return -1 ;
497
501
}
498
502
max = min ;
@@ -501,19 +505,21 @@ static int fpm_setcpuaffinity(char *cpu_list)
501
505
char * err ;
502
506
max = strtol (cpu_listsep + 1 , & err , 0 );
503
507
if (errno || * err != '\0' || max < min || max > cpumax ) {
508
+ efree (ptr );
504
509
return -1 ;
505
510
}
506
511
} else {
512
+ efree (ptr );
507
513
return -1 ;
508
514
}
509
515
}
510
516
511
517
fpm_cpuaffinity_add (& c , min , max );
512
-
513
- token = php_strtok_r (NULL , ";" , & buf );
518
+ token = php_strtok_r (NULL , "," , & buf );
514
519
}
515
520
516
521
r = fpm_cpuaffinity_set (& c );
522
+ efree (ptr );
517
523
return r ;
518
524
}
519
525
#endif
0 commit comments