summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul de Weerd <weerd@cvs.openbsd.org>2008-12-02 00:42:42 +0000
committerPaul de Weerd <weerd@cvs.openbsd.org>2008-12-02 00:42:42 +0000
commit427b465ac0f48fa76bea2fa37c0bf8a3dc4f2036 (patch)
tree4caff9c038e6e43fede893b6407bc2eb39020dfd
parent35d822e4fdd9c8e5985b9baa0f68d35ffd6588dc (diff)
Do not write warnings, errors or debug messages to stdout; it breaks
filesystem extraction (-x) with debug binaries. Found with Nick Bender at OpenCON. 'Go for it' deraadt@
-rw-r--r--distrib/common/elfrdsetroot.c31
-rw-r--r--distrib/common/rdsetroot.c55
2 files changed, 45 insertions, 41 deletions
diff --git a/distrib/common/elfrdsetroot.c b/distrib/common/elfrdsetroot.c
index 9adbb20c3e4..4ddec06c42c 100644
--- a/distrib/common/elfrdsetroot.c
+++ b/distrib/common/elfrdsetroot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: elfrdsetroot.c,v 1.14 2008/12/02 00:40:20 deraadt Exp $ */
+/* $OpenBSD: elfrdsetroot.c,v 1.15 2008/12/02 00:42:41 weerd Exp $ */
/* $NetBSD: rdsetroot.c,v 1.2 1995/10/13 16:38:39 gwr Exp $ */
/*
@@ -106,12 +106,12 @@ main(int argc, char *argv[])
n = read(fd, &eh, sizeof(eh));
if (n < sizeof(eh)) {
- printf("%s: reading header\n", file);
+ fprintf(stderr, "%s: reading header\n", file);
exit(1);
}
if (!IS_ELF(eh)) {
- printf("%s: not elf\n", file);
+ fprintf(stderr, "%s: not elf\n", file);
exit(1);
}
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
ph = (Elf_Phdr *)malloc(phsize);
lseek(fd, eh.e_phoff, SEEK_SET);
if (read(fd, (char *)ph, phsize) != phsize) {
- printf("%s: can't read phdr area\n", file);
+ fprintf(stderr, "%s: can't read phdr area\n", file);
exit(1);
}
@@ -128,7 +128,8 @@ main(int argc, char *argv[])
found = find_rd_root_image(file, &eh, &ph[n], n);
}
if (!found) {
- printf("%s: can't locate space for rd_root_image!\n", file);
+ fprintf(stderr, "%s: can't locate space for rd_root_image!\n",
+ file);
exit(1);
}
@@ -139,7 +140,7 @@ main(int argc, char *argv[])
dataseg = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, mmap_offs);
if (dataseg == MAP_FAILED) {
- printf("%s: can not map data seg\n", file);
+ fprintf(stderr, "%s: can not map data seg\n", file);
perror(file);
exit(1);
}
@@ -150,7 +151,7 @@ main(int argc, char *argv[])
ip = (u_int32_t*) (dataseg + rd_root_size_off);
rd_root_size_val = *ip;
#ifdef DEBUG
- printf("rd_root_size val: 0x%08X (%d blocks)\n",
+ fprintf(stderr, "rd_root_size val: 0x%08X (%d blocks)\n",
(u_int32_t)rd_root_size_val,
(u_int32_t)(rd_root_size_val >> 9));
#endif
@@ -159,7 +160,7 @@ main(int argc, char *argv[])
* Copy the symbol table and string table.
*/
#ifdef DEBUG
- printf("copying root image...\n");
+ fprintf(stderr, "copying root image...\n");
#endif
if (xflag) {
n = write(STDOUT_FILENO, dataseg + rd_root_image_off,
@@ -192,7 +193,7 @@ main(int argc, char *argv[])
}
#ifdef DEBUG
- printf("...copied %d bytes\n", n);
+ fprintf(stderr, "...copied %d bytes\n", n);
#endif
close(fd);
exit(0);
@@ -214,7 +215,7 @@ find_rd_root_image(char *file, Elf_Ehdr *eh, Elf_Phdr *ph, int segment)
unsigned long kernel_start, kernel_size;
if (nlist(file, wantsyms)) {
- printf("%s: no rd_root_image symbols?\n", file);
+ fprintf(stderr, "%s: no rd_root_image symbols?\n", file);
exit(1);
}
kernel_start = ph->p_paddr;
@@ -226,13 +227,14 @@ find_rd_root_image(char *file, Elf_Ehdr *eh, Elf_Phdr *ph, int segment)
rd_root_image_off -= (ph->p_vaddr - ph->p_paddr);
#ifdef DEBUG
- printf("segment %d rd_root_size_off = 0x%x\n", segment, rd_root_size_off);
+ fprintf(stderr, "segment %d rd_root_size_off = 0x%x\n", segment,
+ rd_root_size_off);
if ((ph->p_vaddr - ph->p_paddr) != 0)
- printf("root_off v %x p %x, diff %x altered %x\n",
+ fprintf(stderr, "root_off v %x p %x, diff %x altered %x\n",
ph->p_vaddr, ph->p_paddr,
(ph->p_vaddr - ph->p_paddr),
rd_root_size_off - (ph->p_vaddr - ph->p_paddr));
- printf("rd_root_image_off = 0x%x\n", rd_root_image_off);
+ fprintf(stderr, "rd_root_image_off = 0x%x\n", rd_root_image_off);
#endif
/*
@@ -241,7 +243,8 @@ find_rd_root_image(char *file, Elf_Ehdr *eh, Elf_Phdr *ph, int segment)
if (rd_root_image_off < 0 || rd_root_image_off >= kernel_size)
return(0);
if (rd_root_size_off < 0 || rd_root_size_off >= kernel_size) {
- printf("%s: rd_root_size not in data segment?\n", file);
+ fprintf(stderr, "%s: rd_root_size not in data segment?\n",
+ file);
return(0);
}
mmap_offs = ph->p_offset;
diff --git a/distrib/common/rdsetroot.c b/distrib/common/rdsetroot.c
index b22d639eaad..f553a5f00ee 100644
--- a/distrib/common/rdsetroot.c
+++ b/distrib/common/rdsetroot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rdsetroot.c,v 1.12 2008/12/02 00:40:20 deraadt Exp $ */
+/* $OpenBSD: rdsetroot.c,v 1.13 2008/12/02 00:42:41 weerd Exp $ */
/* $NetBSD: rdsetroot.c,v 1.2 1995/10/13 16:38:39 gwr Exp $ */
/*
@@ -96,31 +96,31 @@ main(int argc, char *argv[])
n = read(fd, &head, sizeof(head));
if (n < sizeof(head)) {
- printf("%s: reading header\n", file);
+ fprintf(stderr, "%s: reading header\n", file);
exit(1);
}
if (N_BADMAG(head)) {
- printf("%s: bad magic number\n", file);
+ fprintf(stderr, "%s: bad magic number\n", file);
exit(1);
}
#ifdef DEBUG
- printf(" text: %9d\n", head.a_text);
- printf(" data: %9d\n", head.a_data);
- printf(" bss: %9d\n", head.a_bss);
- printf(" syms: %9d\n", head.a_syms);
- printf("entry: 0x%08X\n", head.a_entry);
- printf("trsiz: %9d\n", head.a_trsize);
- printf("drsiz: %9d\n", head.a_drsize);
+ fprintf(stderr, " text: %9d\n", head.a_text);
+ fprintf(stderr, " data: %9d\n", head.a_data);
+ fprintf(stderr, " bss: %9d\n", head.a_bss);
+ fprintf(stderr, " syms: %9d\n", head.a_syms);
+ fprintf(stderr, "entry: 0x%08X\n", head.a_entry);
+ fprintf(stderr, "trsiz: %9d\n", head.a_trsize);
+ fprintf(stderr, "drsiz: %9d\n", head.a_drsize);
#endif
if (head.a_syms <= 0) {
- printf("%s: no symbols\n", file);
+ fprintf(stderr, "%s: no symbols\n", file);
exit(1);
}
if (head.a_trsize || head.a_drsize) {
- printf("%s: has relocations\n", file);
+ fprintf(stderr, "%s: has relocations\n", file);
exit(1);
}
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
dataseg = mmap(NULL, data_len, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, data_off);
if (dataseg == MAP_FAILED) {
- printf("%s: can not map data seg\n", file);
+ fprintf(stderr, "%s: can not map data seg\n", file);
perror(file);
exit(1);
}
@@ -163,7 +163,7 @@ main(int argc, char *argv[])
ip = (int*) (dataseg + rd_root_size_off);
rd_root_size_val = *ip;
#ifdef DEBUG
- printf("rd_root_size val: 0x%08X (%d blocks)\n",
+ fprintf(stderr, "rd_root_size val: 0x%08X (%d blocks)\n",
rd_root_size_val, (rd_root_size_val >> 9));
#endif
@@ -171,7 +171,7 @@ main(int argc, char *argv[])
* Copy the symbol table and string table.
*/
#ifdef DEBUG
- printf("copying root image...\n");
+ fprintf(stderr, "copying root image...\n");
#endif
if (xflag) {
n = write(STDOUT_FILENO, dataseg + rd_root_image_off,
@@ -203,7 +203,7 @@ main(int argc, char *argv[])
}
#ifdef DEBUG
- printf("...copied %d bytes\n", n);
+ fprintf(stderr, "copied %d bytes\n", n);
#endif
close(fd);
exit(0);
@@ -225,37 +225,38 @@ find_rd_root_image(char *file)
int data_va, std_entry;
if (nlist(file, wantsyms)) {
- printf("%s: no rd_root_image symbols?\n", file);
+ fprintf(stderr, "%s: no rd_root_image symbols?\n", file);
exit(1);
}
std_entry = N_TXTADDR(head) + (head.a_entry & (N_PAGSIZ(head)-1));
data_va = N_DATADDR(head);
if (head.a_entry != std_entry) {
- printf("%s: warning: non-standard entry point: 0x%08x\n",
- file, head.a_entry);
- printf("\texpecting entry=0x%X\n", std_entry);
+ fprintf(stderr,
+ "%s: warning: non-standard entry point: 0x%08x\n", file
+ head.a_entry);
+ fprintf(stderr, "\texpecting entry=0x%X\n", std_entry);
data_va += (head.a_entry - std_entry);
}
rd_root_size_off = wantsyms[0].n_value - data_va;
rd_root_image_off = wantsyms[1].n_value - data_va;
#ifdef DEBUG
- printf(".data segment va: 0x%08X\n", data_va);
- printf("rd_root_size va: 0x%08X\n", wantsyms[0].n_value);
- printf("rd_root_image va: 0x%08X\n", wantsyms[1].n_value);
- printf("rd_root_size off: 0x%08X\n", rd_root_size_off);
- printf("rd_root_image off: 0x%08X\n", rd_root_image_off);
+ fprintf(stderr, "data segment va: 0x%08X\n", data_va);
+ fprintf(stderr, "rd_root_size va: 0x%08X\n", wantsyms[0].n_value);
+ fprintf(stderr, "rd_root_image va: 0x%08X\n", wantsyms[1].n_value);
+ fprintf(stderr, "rd_root_size off: 0x%08X\n", rd_root_size_off);
+ fprintf(stderr, "rd_root_image off: 0x%08X\n", rd_root_image_off);
#endif
/*
* Sanity check locations of db_* symbols
*/
if (rd_root_image_off < 0 || rd_root_image_off >= head.a_data) {
- printf("%s: rd_root_image not in data segment?\n", file);
+ fprintf("%s: rd_root_image not in data segment?\n", file);
exit(1);
}
if (rd_root_size_off < 0 || rd_root_size_off >= head.a_data) {
- printf("%s: rd_root_size not in data segment?\n", file);
+ fprintf("%s: rd_root_size not in data segment?\n", file);
exit(1);
}
}