mcexec: use atobytes() for MCKERNEL_RLIMIT_STACK
This commit is contained in:
@ -1280,6 +1280,7 @@ unsigned long atobytes(char *string)
|
|||||||
{
|
{
|
||||||
unsigned long mult = 1;
|
unsigned long mult = 1;
|
||||||
char *postfix;
|
char *postfix;
|
||||||
|
errno = ERANGE;
|
||||||
|
|
||||||
if (!strlen(string)) {
|
if (!strlen(string)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -1300,6 +1301,7 @@ unsigned long atobytes(char *string)
|
|||||||
*postfix = 0;
|
*postfix = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
return atol(string) * mult;
|
return atol(string) * mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1650,20 +1652,38 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
p = getenv(rlimit_stack_envname);
|
p = getenv(rlimit_stack_envname);
|
||||||
if (p) {
|
if (p) {
|
||||||
|
char *saveptr;
|
||||||
|
char *token;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
lcur = strtoul(p, &p, 0);
|
|
||||||
if (errno || (*p != ',')) {
|
token = strtok_r(p, ",", &saveptr);
|
||||||
fprintf(stderr, "Error: Failed to parse %s\n",
|
if (!token) {
|
||||||
|
fprintf(stderr, "Error: Failed to parse %s 1\n",
|
||||||
rlimit_stack_envname);
|
rlimit_stack_envname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
errno = 0;
|
|
||||||
lmax = strtoul(p+1, &p, 0);
|
lcur = atobytes(token);
|
||||||
if (errno || (*p != '\0')) {
|
if (lcur == 0 || errno) {
|
||||||
fprintf(stderr, "Error: Failed to parse %s\n",
|
fprintf(stderr, "Error: Failed to parse %s 2\n",
|
||||||
rlimit_stack_envname);
|
rlimit_stack_envname);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, ",", &saveptr);
|
||||||
|
if (!token) {
|
||||||
|
fprintf(stderr, "Error: Failed to parse %s 4\n",
|
||||||
|
rlimit_stack_envname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lmax = atobytes(token);
|
||||||
|
if (lmax == 0 || errno) {
|
||||||
|
fprintf(stderr, "Error: Failed to parse %s 5\n",
|
||||||
|
rlimit_stack_envname);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (lcur > lmax) {
|
if (lcur > lmax) {
|
||||||
lcur = lmax;
|
lcur = lmax;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user