summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-18 15:22:30 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-18 15:22:30 +0200
commitfdcfacaf4a570edeb39b464827a11e8c8fb62835 (patch)
tree6507caab2cc6f4070b872eb5748048b234bba0bb
parent5187c478439e34cdacf8bc9c2648fb7cb7f30eb3 (diff)
use EBADMSG to signal invalid input files
-rw-r--r--src/coredump-util.c20
-rw-r--r--src/minidump.h10
-rw-r--r--src/mkminidump.c4
-rw-r--r--src/read-minidump.c24
4 files changed, 30 insertions, 28 deletions
diff --git a/src/coredump-util.c b/src/coredump-util.c
index 468d54a..bbfd77a 100644
--- a/src/coredump-util.c
+++ b/src/coredump-util.c
@@ -43,43 +43,43 @@ int coredump_read_header(int fd, ElfW(Ehdr) *header) {
return -EIO;
if (memcmp(header->e_ident, ELFMAG, SELFMAG) != 0)
- return -EINVAL;
+ return -EBADMSG;
if (header->e_type != ET_CORE)
- return -EINVAL;
+ return -EBADMSG;
if (header->e_ehsize != sizeof(ElfW(Ehdr)))
- return -EINVAL;
+ return -EBADMSG;
if (header->e_phentsize != sizeof(ElfW(Phdr)))
- return -EINVAL;
+ return -EBADMSG;
#if __WORDSIZE == 32
if (header->e_ident[EI_CLASS] != ELFCLASS32)
- return -EINVAL;
+ return -EBADMSG;
#elif __WORDSIZE == 64
if (header->e_ident[EI_CLASS] != ELFCLASS64)
- return -EINVAL;
+ return -EBADMSG;
#else
#error "Unknown word size."
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
if (header->e_ident[EI_DATA] != ELFDATA2LSB)
- return -EINVAL;
+ return -EBADMSG;
#elif __BYTE_ORDER == __BIG_ENDIAN
if (header->e_ident[EI_DATA] != ELFDATA2MSB)
- return -EINVAL;
+ return -EBADMSG;
#else
#error "Unknown endianess."
#endif
#if defined(__i386)
if (header->e_machine != EM_386)
- return -EINVAL;
+ return -EBADMSG;
#elif defined(__x86_64)
if (header->e_machine != EM_X86_64)
- return -EINVAL;
+ return -EBADMSG;
#else
#error "Unknown machine."
#endif
diff --git a/src/minidump.h b/src/minidump.h
index 99bfe76..824af4f 100644
--- a/src/minidump.h
+++ b/src/minidump.h
@@ -29,7 +29,7 @@
/* Terms:
*
* coredump: an ELF coredump as generated by the kernel
- * minicore: an reduced size ELF coredump, augmented with userspace data
+ * minicore: a reduced size ELF coredump, augmented with userspace data
* minidump: a Windows/Breakpad compatible minidump
*
* We can convert:
@@ -43,17 +43,19 @@
* A minidump → minicore
*
* A minicore may be used as input wherever a coredump is expected.
+ *
+ * The input coredump/minidump fds must be seekable.
*/
-/* You may set either pid = 0 or coredump_fd = -1 */
+/* You may set either pid = 0 or coredump_fd = -1 but not both*/
int minidump_make(pid_t pid, int coredump_fd, void **minidump, size_t *size);
-/* You may set either pid = 0 or coredump_fd = -1 */
+/* You may set either pid = 0 or coredump_fd = -1 but not both */
int minicore_make(pid_t pid, int coredump_fd, void **minicore, size_t *size);
int minidump_show(FILE *f, int minidump_fd);
-/* You may set either pid = 0 or coredump_fd = -1 */
+/* You may set either pid = 0 or coredump_fd = -1 but not both */
int coredump_show(FILE *f, pid_t pid, int coredump_fd);
int minidump_to_minicore(int minidump_fd, void **minicore, size_t *size);
diff --git a/src/mkminidump.c b/src/mkminidump.c
index 2fd1000..f6bda6e 100644
--- a/src/mkminidump.c
+++ b/src/mkminidump.c
@@ -253,7 +253,7 @@ int main(int argc, char *argv[]) {
if (arg_minicore) {
r = minidump_to_minicore(fd, &buffer, &buffer_size);
- if (r == -EINVAL)
+ if (r == -EBADMSG)
r = minicore_make(0, fd, &buffer, &buffer_size);
if (r < 0) {
@@ -281,7 +281,7 @@ int main(int argc, char *argv[]) {
if (!arg_minidump && !arg_minicore) {
r = minidump_show(stdout, fd);
- if (r == -EINVAL)
+ if (r == -EBADMSG)
r = coredump_show(stdout, 0, fd);
if (r < 0) {
diff --git a/src/read-minidump.c b/src/read-minidump.c
index f9a96ac..87c7fe2 100644
--- a/src/read-minidump.c
+++ b/src/read-minidump.c
@@ -27,17 +27,6 @@
#include "context.h"
#include "read-minidump.h"
-int minidump_read_memory(struct context *c, unsigned long source, void *destination, size_t length) {
- assert(c);
- assert(destination);
- assert(length > 0);
- assert(CONTEXT_HAVE_MINIDUMP(c));
-
- /* FIXME */
-
- return -ENOTSUP;
-}
-
int minidump_read_header(struct context *c) {
ssize_t l;
@@ -51,13 +40,24 @@ int minidump_read_header(struct context *c) {
return -EIO;
if (c->minidump_header.signature != htole32(0x504d444d))
- return -EINVAL;
+ return -EBADMSG;
c->have_minidump_header = true;
return 0;
}
+int minidump_read_memory(struct context *c, unsigned long source, void *destination, size_t length) {
+ assert(c);
+ assert(destination);
+ assert(length > 0);
+ assert(CONTEXT_HAVE_MINIDUMP(c));
+
+ /* FIXME */
+
+ return -ENOTSUP;
+}
+
int minidump_read_threads(struct context *c) {
assert(c);
assert(CONTEXT_HAVE_MINIDUMP(c));