Module: kamailio
Branch: master
Commit: 1b7ea63df655246b5b6ca123d9ed25d1764d9402
URL:
https://github.com/kamailio/kamailio/commit/1b7ea63df655246b5b6ca123d9ed25d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-12-11T15:37:26+01:00
core: main - check limit for values of -m and -M
---
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1b7ea63df655246b5b6ca123d9ed25d…
Patch:
https://github.com/kamailio/kamailio/commit/1b7ea63df655246b5b6ca123d9ed25d…
---
diff --git a/src/main.c b/src/main.c
index db694381421..3aa79b73d91 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2094,6 +2094,7 @@ int main(int argc, char **argv)
struct name_lst *n_lst;
char *p;
struct stat st = {0};
+ long l1 = 0;
#define KSR_TBUF_SIZE 512
char tbuf[KSR_TBUF_SIZE];
@@ -2181,12 +2182,20 @@ int main(int argc, char **argv)
fprintf(stderr, "bad private mem size\n");
goto error;
}
- pkg_mem_size = strtol(optarg, &tmp, 10) * 1024 * 1024;
+ l1 = strtol(optarg, &tmp, 10);
if(tmp && (*tmp)) {
fprintf(stderr, "bad private mem size number: -M %s\n",
optarg);
goto error;
- };
+ }
+ /* safety check for upper limit of 1TB */
+ if(l1 <= 0 || l1 > 1024L * 1024) {
+ fprintf(stderr,
+ "our of limits private mem size number: -M %s\n",
+ optarg);
+ goto error;
+ }
+ pkg_mem_size = 1024UL * 1024 * l1;
break;
case 'x':
sr_memmng_shm = optarg;
@@ -2315,11 +2324,18 @@ int main(int argc, char **argv)
fprintf(stderr, "bad shared mem size\n");
goto error;
}
- shm_mem_size = strtol(optarg, &tmp, 10) * 1024 * 1024;
+ l1 = strtol(optarg, &tmp, 10);
if(tmp && (*tmp)) {
fprintf(stderr, "bad shmem size number: -m %s\n", optarg);
goto error;
- };
+ }
+ /* safety check for upper limit of 16TB */
+ if(l1 <= 0 || l1 > 16L * 1024 * 1024) {
+ fprintf(stderr, "our of limits shmem size number: -m %s\n",
+ optarg);
+ goto error;
+ }
+ shm_mem_size = 1024UL * 1024 * l1;
LM_INFO("shared memory: %ld bytes\n", shm_mem_size);
break;
case 'd':