diff options
author | H. Peter Anvin <hpa@zytor.com> | 2010-06-19 20:58:25 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2010-06-19 20:58:25 -0700 |
commit | a693d0be3a7b5678c26fcdecd8f4754c784875ac (patch) | |
tree | b16f7d4deb2936daee6c901bff6ebb14aadcb1ca /linux | |
parent | bf0617aecb78a5dbe54962c05d533efd074f7902 (diff) | |
download | syslinux-a693d0be3a7b5678c26fcdecd8f4754c784875ac.tar.gz syslinux-a693d0be3a7b5678c26fcdecd8f4754c784875ac.tar.xz syslinux-a693d0be3a7b5678c26fcdecd8f4754c784875ac.zip |
linux/syslinux: handle the null pathname case
Fix mishandling of the null pathname case in the syslinux installer,
and generally clean up the handling of the subpath name.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'linux')
-rw-r--r-- | linux/syslinux.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/linux/syslinux.c b/linux/syslinux.c index 888df3d9..20de62ae 100644 --- a/linux/syslinux.c +++ b/linux/syslinux.c @@ -1,6 +1,7 @@ /* ----------------------------------------------------------------------- * * * Copyright 1998-2008 H. Peter Anvin - All Rights Reserved + * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -281,11 +282,19 @@ int main(int argc, char *argv[]) umask(077); parse_options(argc, argv, MODE_SYSLINUX); - asprintf(&subdir, "%s%s", - opt.directory[0] == '/' ? "" : "/", opt.directory); - if (!subdir) { - perror(program); - exit(1); + /* Note: subdir is guaranteed to start and end in / */ + if (opt.directory && opt.directory[0]) { + int len = strlen(opt.directory); + asprintf(&subdir, "%s%s%s", + opt.directory[0] == '/' ? "" : "/", + opt.directory, + opt.directory[len-1] == '/' ? "" : "/"); + if (!subdir) { + perror(program); + exit(1); + } + } else { + subdir = "/"; } if (!opt.device) @@ -377,9 +386,8 @@ int main(int argc, char *argv[]) die("mount failed"); } - ldlinux_path = alloca(strlen(mntpath) + (subdir ? strlen(subdir) + 2 : 0)); - sprintf(ldlinux_path, "%s%s%s", - mntpath, subdir ? "//" : "", subdir ? subdir : ""); + ldlinux_path = alloca(strlen(mntpath) + strlen(subdir) + 1); + sprintf(ldlinux_path, "%s%s", mntpath, subdir); ldlinux_name = alloca(strlen(ldlinux_path) + 14); if (!ldlinux_name) { @@ -387,7 +395,7 @@ int main(int argc, char *argv[]) err = 1; goto umount; } - sprintf(ldlinux_name, "%s//ldlinux.sys", ldlinux_path); + sprintf(ldlinux_name, "%sldlinux.sys", ldlinux_path); /* update ADV only ? */ if (opt.update_only == -1) { |