Hung-Te Lin (hungte@chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2203
-gerrit
commit 196f206cbbb2d45ace01a0953faf280704c12beb Author: Hung-Te Lin hungte@chromium.org Date: Mon Jan 28 23:42:25 2013 +0800
cbfstool: Use non-intrusive basename().
Calling basename may modify content, so we should implement an alternative to prevent corrupting file names.
Change-Id: Ib4827f887542596feef16e7829b00444220b9922 Signed-off-by: Hung-Te Lin hungte@chromium.org --- util/cbfstool/common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index bf4f7b0..c442159 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -22,7 +22,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <libgen.h> #include "common.h" #include "cbfs.h" #include "elf.h" @@ -282,11 +281,20 @@ uint64_t intfiletype(const char *name) return -1; }
+/* basename(3) may modify buffer, so we should use a tiny alternative. */ +static const char *simple_basename(const char *name) { + const char *slash = strrchr(name, '/'); + if (slash) + return slash + 1; + else + return name; +} + void print_cbfs_directory(const char *filename) { printf("%s: %d kB, bootblocksize %d, romsize %d, offset 0x%x\n" "alignment: %d bytes, architecture: %s\n\n", - basename((char *)filename), romsize / 1024, + simple_basename(filename), romsize / 1024, ntohl(master_header->bootblocksize), romsize, ntohl(master_header->offset), align, arch_to_string(arch));