Skip to content

Commit

Permalink
Add google break pad support (only tested under Android)
Browse files Browse the repository at this point in the history
also add crash option to test it

Signed-off-by: Arne Schwabe <[email protected]>
  • Loading branch information
schwabe committed Dec 4, 2024
1 parent 700b8a7 commit ee0100b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/openvpn/breakpad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#include "breakpad.h"
#include "client/linux/handler/exception_handler.h"


static
bool DumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void* context,
bool succeeded) {
printf("Dump path: %s\n", descriptor.path());
fflush(stdout);
fflush(stderr);
return succeeded;
}

static google_breakpad::MinidumpDescriptor* desc;
static google_breakpad::ExceptionHandler* eh;

void breakpad_setup(void)
{
printf("Initializing Google Breakpad!\n");
desc = new google_breakpad::MinidumpDescriptor("/data/data/de.blinkt.openvpn/cache");
eh = new google_breakpad::ExceptionHandler(*desc, NULL, DumpCallback, NULL, true,-1);
}

void breakpad_dodump(void)
{
eh->WriteMinidump();
}
12 changes: 12 additions & 0 deletions src/openvpn/breakpad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif
void breakpad_setup(void);

void breakpad_dodump(void);

#ifdef __cplusplus
}
#endif
18 changes: 16 additions & 2 deletions src/openvpn/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#endif
#endif

#ifdef GOOGLE_BREAKPAD
#include "breakpad.h"
#endif

/* Globals */
unsigned int x_debug_level; /* GLOBAL */

Expand Down Expand Up @@ -441,15 +445,25 @@ dont_mute(unsigned int flags)
void
assert_failed(const char *filename, int line, const char *condition)
{
#ifdef GOOGLE_BREAKPAD
int level = M_ERR;
#else
int level = M_FATAL;
#endif
if (condition)
{
msg(M_FATAL, "Assertion failed at %s:%d (%s)", filename, line, condition);
msg(level, "Assertion failed at %s:%d (%s)", filename, line, condition);
}
else
{
msg(M_FATAL, "Assertion failed at %s:%d", filename, line);
msg(level, "Assertion failed at %s:%d", filename, line);
}
_exit(1);

#ifdef GOOGLE_BREAKPAD
breakpad_dodump();
#endif
_exit(1);
}

/*
Expand Down
8 changes: 8 additions & 0 deletions src/openvpn/openvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

#define P2P_CHECK_SIG() EVENT_LOOP_CHECK_SIGNAL(c, process_signal_p2p, c);

#ifdef GOOGLE_BREAKPAD
#include "breakpad.h"
#endif

static bool
process_signal_p2p(struct context *c)
{
Expand Down Expand Up @@ -392,6 +396,10 @@ wmain(int argc, wchar_t *wargv[])
int
main(int argc, char *argv[])
{
#ifdef GOOGLE_BREAKPAD
breakpad_setup();
#endif

return openvpn_main(argc, argv);
}
#endif /* ifdef _WIN32 */
5 changes: 5 additions & 0 deletions src/openvpn/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -8637,6 +8637,11 @@ add_option(struct options *options,
VERIFY_PERMISSION(OPT_P_NCP|OPT_P_INSTANCE);
options->ciphername = p[1];
}
else if (streq(p[0], "crash"))
{
VERIFY_PERMISSION(OPT_P_GENERAL);
*((int *) 28) = 27;
}
else if (streq(p[0], "data-ciphers-fallback") && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_INSTANCE);
Expand Down

0 comments on commit ee0100b

Please sign in to comment.