summaryrefslogtreecommitdiff
path: root/dbutil.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2018-02-17 19:29:51 +0800
committerMatt Johnston <matt@ucc.asn.au>2018-02-17 19:29:51 +0800
commit104e39e9caf447cb416a6d83ea7eedd4481ce4c3 (patch)
treeb8b33aaee9f7336e592da7a916ee05bae3412c22 /dbutil.c
parent2b551518f8625f87a22ea1fde40e3c7d841bf9d0 (diff)
parent769be133237df6d9a4028645e7e9924be8544c8f (diff)
downloaddropbear-104e39e9caf447cb416a6d83ea7eedd4481ce4c3.tar.gz
merge from main
Diffstat (limited to 'dbutil.c')
-rw-r--r--dbutil.c65
1 files changed, 26 insertions, 39 deletions
diff --git a/dbutil.c b/dbutil.c
index 18fe634..73c7cb2 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -120,6 +120,13 @@ static void generic_dropbear_exit(int exitcode, const char* format,
_dropbear_log(LOG_INFO, fmtbuf, param);
+#ifdef DROPBEAR_FUZZ
+ // longjmp before cleaning up svr_opts
+ if (fuzz.do_jmp) {
+ longjmp(fuzz.jmp, 1);
+ }
+#endif
+
exit(exitcode);
}
@@ -392,6 +399,7 @@ void printhex(const char * label, const unsigned char * buf, int len) {
void printmpint(const char *label, mp_int *mp) {
buffer *buf = buf_new(1000);
buf_putmpint(buf, mp);
+ fprintf(stderr, "%d bits ", mp_count_bits(mp));
printhex(label, buf->data, buf->len);
buf_free(buf);
@@ -520,57 +528,26 @@ void m_close(int fd) {
}
}
-void * m_malloc(size_t size) {
-
- void* ret;
-
- if (size == 0) {
- dropbear_exit("m_malloc failed");
- }
- ret = calloc(1, size);
- if (ret == NULL) {
- dropbear_exit("m_malloc failed");
- }
- return ret;
-
-}
-
-void * m_strdup(const char * str) {
- char* ret;
-
- ret = strdup(str);
- if (ret == NULL) {
- dropbear_exit("m_strdup failed");
- }
- return ret;
-}
-
-void * m_realloc(void* ptr, size_t size) {
-
- void *ret;
-
- if (size == 0) {
- dropbear_exit("m_realloc failed");
- }
- ret = realloc(ptr, size);
- if (ret == NULL) {
- dropbear_exit("m_realloc failed");
- }
- return ret;
-}
-
void setnonblocking(int fd) {
TRACE(("setnonblocking: %d", fd))
+#ifdef DROPBEAR_FUZZ
+ if (fuzz.fuzzing) {
+ return;
+ }
+#endif
+
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
if (errno == ENODEV) {
/* Some devices (like /dev/null redirected in)
* can't be set to non-blocking */
TRACE(("ignoring ENODEV for setnonblocking"))
} else {
+ {
dropbear_exit("Couldn't set nonblocking");
}
+ }
}
TRACE(("leave setnonblocking"))
}
@@ -652,7 +629,14 @@ static clockid_t get_linux_clock_source() {
#endif
time_t monotonic_now() {
+#ifdef DROPBEAR_FUZZ
+ if (fuzz.fuzzing) {
+ /* time stands still when fuzzing */
+ return 5;
+ }
+#endif
#if defined(__linux__) && defined(SYS_clock_gettime)
+ {
static clockid_t clock_source = -2;
if (clock_source == -2) {
@@ -669,9 +653,11 @@ time_t monotonic_now() {
}
return ts.tv_sec;
}
+ }
#endif /* linux clock_gettime */
#if defined(HAVE_MACH_ABSOLUTE_TIME)
+ {
/* OS X, see https://developer.apple.com/library/mac/qa/qa1398/_index.html */
static mach_timebase_info_data_t timebase_info;
if (timebase_info.denom == 0) {
@@ -679,6 +665,7 @@ time_t monotonic_now() {
}
return mach_absolute_time() * timebase_info.numer / timebase_info.denom
/ 1e9;
+ }
#endif /* osx mach_absolute_time */
/* Fallback for everything else - this will sometimes go backwards */