36
36
#include <selinux/selinux.h>
37
37
#endif
38
38
39
- #ifdef HAVE_SCHED_H
39
+ #if defined( HAVE_SCHED_H )
40
40
#include <sched.h>
41
- #endif
42
-
43
- #ifdef HAVE_SYS_CPUSET_H
41
+ #elif defined(HAVE_SYS_CPUSET_H )
44
42
#include <sys/cpuset.h>
45
43
typedef cpuset_t cpu_set_t ;
46
44
#endif
@@ -449,21 +447,27 @@ static int fpm_cpuaffinity_set(cpu_set_t *c)
449
447
450
448
static int fpm_setcpuaffinity (char * cpu_list )
451
449
{
452
- char * token , * buf ;
450
+ char * token , * buf , * ptr ;
453
451
cpu_set_t c ;
454
452
int r , cpumax , min , max ;
455
453
456
454
r = -1 ;
457
455
cpumax = fpm_cpumax ();
458
456
459
457
fpm_cpuaffinity_init (& c );
460
- token = php_strtok_r (cpu_list , "," , & buf );
458
+ ptr = estrdup (cpu_list );
459
+ token = php_strtok_r (ptr , "," , & buf );
461
460
462
461
while (token ) {
463
462
char * cpu_listsep ;
464
463
464
+ if (!isdigit (* token )) {
465
+ return -1 ;
466
+ }
467
+
465
468
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 );
467
471
return -1 ;
468
472
}
469
473
max = min ;
@@ -472,19 +476,21 @@ static int fpm_setcpuaffinity(char *cpu_list)
472
476
char * err ;
473
477
max = strtol (cpu_listsep + 1 , & err , 0 );
474
478
if (errno || * err != '\0' || max < min || max > cpumax ) {
479
+ efree (ptr );
475
480
return -1 ;
476
481
}
477
482
} else {
483
+ efree (ptr );
478
484
return -1 ;
479
485
}
480
486
}
481
487
482
488
fpm_cpuaffinity_add (& c , min , max );
483
-
484
- token = php_strtok_r (NULL , ";" , & buf );
489
+ token = php_strtok_r (NULL , "," , & buf );
485
490
}
486
491
487
492
r = fpm_cpuaffinity_set (& c );
493
+ efree (ptr );
488
494
return r ;
489
495
}
490
496
#endif
0 commit comments