aboutsummaryrefslogtreecommitdiffstats
path: root/com32/elflink/ldlinux
diff options
context:
space:
mode:
Diffstat (limited to 'com32/elflink/ldlinux')
-rw-r--r--com32/elflink/ldlinux/Makefile12
-rw-r--r--com32/elflink/ldlinux/kernel.c64
2 files changed, 52 insertions, 24 deletions
diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile
index aa35f475..659aa405 100644
--- a/com32/elflink/ldlinux/Makefile
+++ b/com32/elflink/ldlinux/Makefile
@@ -20,10 +20,12 @@ OBJS = ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o adv.o \
execute.o chainboot.o kernel.o get_key.o advwrite.o setadv.o \
eprintf.o loadhigh.o msg.o
-all: ldlinux.c32 ldlinux_lnx.a
+BTARGET = ldlinux.c32
+
+all: $(BTARGET) ldlinux_lnx.a
ldlinux.c32 : $(OBJS)
- $(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
+ $(LD) $(LDFLAGS) -soname $(@F) -o $@ $^ $(LIBS)
LNXCFLAGS += -D__export='__attribute__((visibility("default")))'
LNXLIBOBJS = get_key.lo
@@ -36,14 +38,14 @@ tidy dist:
rm -f *.o *.lo *.a *.lst .*.d
clean: tidy
- rm -f *.lss *.lnx *.com *.c32
+ rm -f *.lss *.lnx *.com
spotless: clean
- rm -f *~ \#*
+ rm -f *~ \#* $(BTARGET)
install: all
mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
- install -m 644 ldlinux.c32 $(INSTALLROOT)$(AUXDIR)
+ install -m 644 $(BTARGET) $(INSTALLROOT)$(AUXDIR)
-include .*.d
diff --git a/com32/elflink/ldlinux/kernel.c b/com32/elflink/ldlinux/kernel.c
index 1cfb6508..920246fc 100644
--- a/com32/elflink/ldlinux/kernel.c
+++ b/com32/elflink/ldlinux/kernel.c
@@ -15,35 +15,45 @@ const char *append = NULL;
/* Will be called from readconfig.c */
int new_linux_kernel(char *okernel, char *ocmdline)
{
- const char *kernel_name = NULL;
+ const char *kernel_name = NULL, *args = NULL;
struct initramfs *initramfs = NULL;
char *temp;
void *kernel_data;
- size_t kernel_len;
+ size_t kernel_len, cmdline_len;
bool opt_quiet = false;
- char initrd_name[256];
- char cmdline_buf[256], *cmdline;
+ char *initrd_name, *cmdline;
dprintf("okernel = %s, ocmdline = %s", okernel, ocmdline);
- cmdline = cmdline_buf;
-
- temp = cmdline;
-
if (okernel)
kernel_name = okernel;
else if (globaldefault)
kernel_name = globaldefault;
- strcpy(temp, kernel_name);
- temp += strlen(kernel_name);
-
- *temp = ' ';
- temp++;
if (ocmdline)
- strcpy(temp, ocmdline);
+ args = ocmdline;
else if (append)
- strcpy(temp, append);
+ args = append;
+
+ cmdline_len = strlen(kernel_name);
+ if (args) {
+ /* +1 for the space (' ') between kernel and args */
+ cmdline_len += strlen(args) + 1;
+ }
+
+ /* +1 for NUL termination */
+ cmdline_len++;
+
+ cmdline = malloc(cmdline_len);
+ if (!cmdline) {
+ printf("Failed to alloc memory for cmdline\n");
+ return 1;
+ }
+
+ if (args)
+ snprintf(cmdline, cmdline_len, "%s %s", kernel_name, args);
+ else
+ snprintf(cmdline, cmdline_len, "%s", kernel_name);
/* "keeppxe" handling */
#if IS_PXELINUX
@@ -79,13 +89,25 @@ int new_linux_kernel(char *okernel, char *ocmdline)
temp += 6; /* strlen("initrd") */
do {
- char *p = initrd_name;
+ size_t n = 0;
+ char *p;
temp++; /* Skip = or , */
- while (*temp != ' ' && *temp != ',' && *temp)
- *p++ = *temp++;
- *p = '\0';
+ p = temp;
+ while (*p != ' ' && *p != ',' && *p) {
+ p++;
+ n++;
+ }
+
+ initrd_name = malloc(n + 1);
+ if (!initrd_name) {
+ printf("Failed to allocate space for initrd\n");
+ goto bail;
+ }
+
+ snprintf(initrd_name, n + 1, "%s", temp);
+ temp += n;
if (!opt_quiet)
printf("Loading %s...", initrd_name);
@@ -93,10 +115,13 @@ int new_linux_kernel(char *okernel, char *ocmdline)
if (initramfs_load_archive(initramfs, initrd_name)) {
if (opt_quiet)
printf("Loading %s ", initrd_name);
+ free(initrd_name);
printf("failed: ");
goto bail;
}
+ free(initrd_name);
+
if (!opt_quiet)
printf("ok\n");
} while (*temp == ',');
@@ -107,6 +132,7 @@ int new_linux_kernel(char *okernel, char *ocmdline)
printf("Booting kernel failed: ");
bail:
+ free(cmdline);
printf("%s\n", strerror(errno));
return 1;
}