config: Misc macro improvements
diff --git a/stage23/lib/config.c b/stage23/lib/config.c
index 24526d86..65e30409 100644
--- a/stage23/lib/config.c
+++ b/stage23/lib/config.c
@@ -192,7 +192,8 @@ int init_config(size_t config_size) {
// Expand macros
if (macros != NULL) {
- char *new_config = ext_mem_alloc(config_size * 4);
+ size_t new_config_size = config_size * 4;
+ char *new_config = ext_mem_alloc(new_config_size);
size_t i, in;
for (i = 0, in = 0; i < config_size;) {
@@ -232,14 +233,24 @@ int init_config(size_t config_size) {
}
pmm_free(macro_name, 1024);
for (j = 0; macro_value[j] != 0; j++, in++) {
+ if (in >= new_config_size) {
+ goto overflow;
+ }
new_config[in] = macro_value[j];
}
continue;
}
+ if (in >= new_config_size) {
+overflow:
+ bad_config = true;
+ panic(true, "config: Macro-induced buffer overflow");
+ }
new_config[in++] = config_addr[i++];
}
+ pmm_free(config_addr, config_size);
+
config_addr = new_config;
config_size = in;
diff --git a/test/limine.cfg b/test/limine.cfg
index 3b456885..bfa3ad38 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -1,3 +1,6 @@
+${STIVALE_KERNEL}=boot:///boot/test.elf
+${BACKGROUND_PATH}=boot:///boot/bg.bmp
+
DEFAULT_ENTRY=1
TIMEOUT=3
GRAPHICS=yes
@@ -5,7 +8,7 @@ VERBOSE=yes
THEME_BACKGROUND=50000000
-BACKGROUND_PATH=boot:///boot/bg.bmp
+BACKGROUND_PATH=${BACKGROUND_PATH}
BACKGROUND_STYLE=stretched
BACKDROP_COLOUR=008080
@@ -16,10 +19,10 @@ COMMENT=Test of the stivale2 boot protocol.
# Let's use autodetection
#PROTOCOL=stivale2
RESOLUTION=800x600
-KERNEL_PATH=boot:///boot/test.elf
+KERNEL_PATH=${STIVALE_KERNEL}
KERNEL_CMDLINE=Woah! Another example!
-MODULE_PATH=boot:///boot/bg.bmp
+MODULE_PATH=${BACKGROUND_PATH}
MODULE_STRING=yooooo
# Test that the module string provided to the kernel will be
