summaryrefslogtreecommitdiff
path: root/dbutil.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2017-06-24 10:34:19 +0800
committerMatt Johnston <matt@ucc.asn.au>2017-06-24 10:34:19 +0800
commit5e3e875e405ad08bad7492377e6b7d9f96cd523a (patch)
tree9bc82bb1cc5c4b4f3896522bd3c7c73b2fb7801a /dbutil.c
parentd514e0b9f44457895c550e8fcca5150239ed0a15 (diff)
parent9fca3b1ce3cc65e724d6ede788c138a1ce5eec27 (diff)
downloaddropbear-5e3e875e405ad08bad7492377e6b7d9f96cd523a.tar.gz
merge from main
Diffstat (limited to 'dbutil.c')
-rw-r--r--dbutil.c64
1 files changed, 25 insertions, 39 deletions
diff --git a/dbutil.c b/dbutil.c
index 830e8d2..aadc20e 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);
}
@@ -520,57 +527,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"))
}
@@ -648,7 +624,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) {
@@ -665,9 +648,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) {
@@ -675,6 +660,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 */