0b8986
--- test/request.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ test/request.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -902,8 +902,6 @@
0b8986
     ONREQ(ne_request_dispatch(req));
0b8986
 
0b8986
     while ((cursor = ne_response_header_iterate(req, cursor, &name, &value))) {
0b8986
-        n = -1;
0b8986
-
0b8986
         ONV(strncmp(name, "x-", 2) || strncmp(value, "Y-", 2)
0b8986
             || strcmp(name + 2, value + 2)
0b8986
             || (n = atoi(name + 2)) >= MANY_HEADERS
0b8986
@@ -2358,6 +2356,21 @@
0b8986
     return await_server();
0b8986
 }
0b8986
 
0b8986
+static int safe_flags(void)
0b8986
+{
0b8986
+    ne_session *sess = ne_session_create("http", "localhost", 80);
0b8986
+    ne_request *req = ne_request_create(sess, "GET", "/");
0b8986
+
0b8986
+    ne_set_request_flag(req, NE_REQFLAG_LAST, 0xAAAAAAAA);
0b8986
+
0b8986
+    ONN("flags array bound check failed", ne_get_session(req) != sess);
0b8986
+
0b8986
+    ne_request_destroy(req);
0b8986
+    ne_session_destroy(sess);
0b8986
+
0b8986
+    return OK;
0b8986
+}
0b8986
+
0b8986
 /* TODO: test that ne_set_notifier(, NULL, NULL) DTRT too. */
0b8986
 
0b8986
 ne_test tests[] = {
0b8986
@@ -2451,5 +2464,6 @@
0b8986
     T(socks_fail),
0b8986
     T(fail_lookup),
0b8986
     T(fail_double_lookup),
0b8986
+    T(safe_flags),
0b8986
     T(NULL)
0b8986
 };
0b8986
--- test/lock.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ test/lock.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -73,11 +73,13 @@
0b8986
 			   const char *token_href)
0b8986
 {
0b8986
     static char buf[BUFSIZ];
0b8986
-    sprintf(buf, 
0b8986
-	    "\n"
0b8986
-	    "<D:prop xmlns:D=\"DAV:\">"
0b8986
-	    "<D:lockdiscovery>%s</D:lockdiscovery></D:prop>\n",
0b8986
-	    activelock(scope, depth, owner, timeout, token_href));
0b8986
+
0b8986
+    ne_snprintf(buf, sizeof buf,
0b8986
+                "\n"
0b8986
+                "<D:prop xmlns:D=\"DAV:\">"
0b8986
+                "<D:lockdiscovery>%s</D:lockdiscovery></D:prop>\n",
0b8986
+                activelock(scope, depth, owner, timeout, token_href));
0b8986
+
0b8986
     return buf;
0b8986
 }
0b8986
 
0b8986
--- test/string-tests.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ test/string-tests.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -320,7 +320,7 @@
0b8986
 {
0b8986
     char expect[200], actual[200];
0b8986
     
0b8986
-    strncpy(expect, strerror(ENOENT), sizeof(expect));
0b8986
+    strncpy(expect, strerror(ENOENT), sizeof(expect)-1);
0b8986
     ONN("ne_strerror did not return passed-in buffer",
0b8986
 	ne_strerror(ENOENT, actual, sizeof(actual)) != actual);
0b8986
     
0b8986
--- test/util-tests.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ test/util-tests.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -203,18 +203,24 @@
0b8986
     return OK;
0b8986
 }
0b8986
 
0b8986
-/* trigger segfaults in ne_rfc1036_parse() in <=0.24.5. */
0b8986
-static int regress_dates(void)
0b8986
+#define BAD_DATE(format, result) \
0b8986
+    ONN(format " date parse must fail", result != -1)
0b8986
+
0b8986
+/* Test for bad dates; trigger segfaults in ne_rfc1036_parse() in
0b8986
+ * <=0.24.5. */
0b8986
+static int bad_dates(void)
0b8986
 {
0b8986
     static const char *dates[] = {
0b8986
-        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
0b8986
+        "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
0b8986
+        "Friday, 08-Jun-01",
0b8986
     };
0b8986
     size_t n;
0b8986
     
0b8986
     for (n = 0; n < sizeof(dates)/sizeof(dates[0]); n++) {
0b8986
-        ne_rfc1036_parse(dates[n]);
0b8986
-        ne_iso8601_parse(dates[n]);
0b8986
-        ne_rfc1123_parse(dates[n]);
0b8986
+        BAD_DATE("rfc1036", ne_rfc1036_parse(dates[n]));
0b8986
+        BAD_DATE("iso8601", ne_iso8601_parse(dates[n]));
0b8986
+        BAD_DATE("rfc1123", ne_rfc1123_parse(dates[n]));
0b8986
+        BAD_DATE("asctime", ne_asctime_parse(dates[n]));
0b8986
     }
0b8986
 
0b8986
     return OK;
0b8986
@@ -303,7 +309,7 @@
0b8986
     T(md5),
0b8986
     T(md5_alignment),
0b8986
     T(parse_dates),
0b8986
-    T(regress_dates),
0b8986
+    T(bad_dates),
0b8986
     T(versioning),
0b8986
     T(version_string),
0b8986
     T(support),
0b8986
--- src/ne_dates.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_dates.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -171,11 +171,12 @@
0b8986
     int n;
0b8986
     time_t result;
0b8986
     
0b8986
-/*  it goes: Sun, 06 Nov 1994 08:49:37 GMT */
0b8986
-    n = sscanf(date, RFC1123_FORMAT,
0b8986
-	    wkday, &gmt.tm_mday, mon, &gmt.tm_year, &gmt.tm_hour,
0b8986
-	    &gmt.tm_min, &gmt.tm_sec);
0b8986
-    /* Is it portable to check n==7 here? */
0b8986
+    /* it goes: Sun, 06 Nov 1994 08:49:37 GMT */
0b8986
+    if (sscanf(date, RFC1123_FORMAT,
0b8986
+               wkday, &gmt.tm_mday, mon, &gmt.tm_year, &gmt.tm_hour,
0b8986
+               &gmt.tm_min, &gmt.tm_sec) != 7)
0b8986
+        return (time_t) -1;
0b8986
+
0b8986
     gmt.tm_year -= 1900;
0b8986
     for (n=0; n<12; n++)
0b8986
 	if (strcmp(mon, short_months[n]) == 0)
0b8986
@@ -204,7 +205,6 @@
0b8986
 	return (time_t)-1;
0b8986
     }
0b8986
 
0b8986
-    /* portable to check n here? */
0b8986
     for (n=0; n<12; n++)
0b8986
 	if (strcmp(mon, short_months[n]) == 0)
0b8986
 	    break;
0b8986
@@ -232,11 +232,12 @@
0b8986
     char wkday[4], mon[4];
0b8986
     time_t result;
0b8986
 
0b8986
-    n = sscanf(date, ASCTIME_FORMAT,
0b8986
-		wkday, mon, &gmt.tm_mday, 
0b8986
-		&gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec,
0b8986
-		&gmt.tm_year);
0b8986
-    /* portable to check n here? */
0b8986
+    if (sscanf(date, ASCTIME_FORMAT,
0b8986
+               wkday, mon, &gmt.tm_mday, 
0b8986
+               &gmt.tm_hour, &gmt.tm_min, &gmt.tm_sec,
0b8986
+               &gmt.tm_year) != 7)
0b8986
+        return (time_t)-1;
0b8986
+
0b8986
     for (n=0; n<12; n++)
0b8986
 	if (strcmp(mon, short_months[n]) == 0)
0b8986
 	    break;
0b8986
--- src/ne_locks.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_locks.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -32,6 +32,7 @@
0b8986
 #ifdef HAVE_LIMITS_H
0b8986
 #include <limits.h>
0b8986
 #endif
0b8986
+#include <assert.h>
0b8986
 
0b8986
 #include <ctype.h> /* for isdigit() */
0b8986
 
0b8986
@@ -332,6 +333,9 @@
0b8986
     for (item = store->locks; item != NULL; item = item->next)
0b8986
 	if (item->lock == lock)
0b8986
 	    break;
0b8986
+
0b8986
+    /* API condition that lock is present in the store. */
0b8986
+    assert(item);
0b8986
     
0b8986
     if (item->prev != NULL) {
0b8986
 	item->prev->next = item->next;
0b8986
--- src/ne_session.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_session.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -569,7 +569,8 @@
0b8986
     };
0b8986
     int n, flag = 0;
0b8986
 
0b8986
-    strcpy(sess->error, _("Server certificate verification failed: "));
0b8986
+    ne_strnzcpy(sess->error, _("Server certificate verification failed: "),
0b8986
+                sizeof sess->error);
0b8986
 
0b8986
     for (n = 0; reasons[n].bit; n++) {
0b8986
 	if (failures & reasons[n].bit) {
0b8986
--- src/ne_xml.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_xml.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -576,7 +576,7 @@
0b8986
         if (p->bom_pos == 0) {
0b8986
             p->bom_pos = 3; /* no BOM */
0b8986
         } else if (p->bom_pos > 0 && p->bom_pos < 3) {
0b8986
-            strcpy(p->error, _("Invalid Byte Order Mark"));
0b8986
+            ne_strnzcpy(p->error, _("Invalid Byte Order Mark"), sizeof p->error);
0b8986
             return p->failure = 1;
0b8986
         }
0b8986
     }
0b8986
--- src/ne_request.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_request.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -329,7 +329,7 @@
0b8986
                 /* errno was set */
0b8986
                 ne_strerror(errno, err, sizeof err);
0b8986
             } else {
0b8986
-                strcpy(err, _("offset invalid"));
0b8986
+                ne_strnzcpy(err, _("offset invalid"), sizeof err);
0b8986
             }
0b8986
             ne_snprintf(offstr, sizeof offstr, "%" FMT_NE_OFF_T,
0b8986
                         req->body.file.offset);
0b8986
@@ -585,7 +585,7 @@
0b8986
 
0b8986
 void ne_set_request_flag(ne_request *req, ne_request_flag flag, int value)
0b8986
 {
0b8986
-    if (flag < (ne_request_flag)NE_SESSFLAG_LAST) {
0b8986
+    if (flag < (ne_request_flag)NE_REQFLAG_LAST) {
0b8986
         req->flags[flag] = value;
0b8986
     }
0b8986
 }
0b8986
--- src/ne_socket.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_socket.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -27,7 +27,7 @@
0b8986
 #include "config.h"
0b8986
 
0b8986
 #include <sys/types.h>
0b8986
-#ifdef HAVE_SYS_UIO_h
0b8986
+#ifdef HAVE_SYS_UIO_H
0b8986
 #include <sys/uio.h> /* writev(2) */
0b8986
 #endif
0b8986
 #ifdef HAVE_SYS_TIME_H
0b8986
--- src/ne_openssl.c	(.../tags/0.30.2)	(revision 2045)
0b8986
+++ src/ne_openssl.c	(.../branches/0.30.x)	(revision 2045)
0b8986
@@ -1130,7 +1130,10 @@
0b8986
     return 0;
0b8986
 }
0b8986
 
0b8986
-#ifdef NE_HAVE_TS_SSL
0b8986
+#if defined(NE_HAVE_TS_SSL) && OPENSSL_VERSION_NUMBER < 0x10101000L
0b8986
+/* For OpenSSL 1.1.1 locking callbacks are no longer need at all. */
0b8986
+#define WITH_OPENSSL_LOCKING (1)
0b8986
+
0b8986
 /* Implementation of locking callbacks to make OpenSSL thread-safe.
0b8986
  * If the OpenSSL API was better designed, this wouldn't be necessary.
0b8986
  * In OpenSSL releases without CRYPTO_set_idptr_callback, it's not
0b8986
@@ -1184,8 +1187,6 @@
0b8986
     }
0b8986
 }
0b8986
 
0b8986
-#endif
0b8986
-
0b8986
 /* ID_CALLBACK_IS_{NEON,OTHER} evaluate as true if the currently
0b8986
  * registered OpenSSL ID callback is the neon function (_NEON), or has
0b8986
  * been overwritten by some other app (_OTHER). */
0b8986
@@ -1196,6 +1197,8 @@
0b8986
 #define ID_CALLBACK_IS_OTHER (CRYPTO_get_id_callback() != NULL)
0b8986
 #define ID_CALLBACK_IS_NEON (CRYPTO_get_id_callback() == thread_id_neon)
0b8986
 #endif
0b8986
+        
0b8986
+#endif /* NE_HAVE_TS_SSL && OPENSSL_VERSION_NUMBER < 1.1.1 */
0b8986
 
0b8986
 int ne__ssl_init(void)
0b8986
 {
0b8986
@@ -1205,7 +1208,7 @@
0b8986
     SSL_library_init();
0b8986
     OpenSSL_add_all_algorithms();
0b8986
 
0b8986
-#ifdef NE_HAVE_TS_SSL
0b8986
+#ifdef WITH_OPENSSL_LOCKING
0b8986
     /* If some other library has already come along and set up the
0b8986
      * thread-safety callbacks, then it must be presumed that the
0b8986
      * other library will have a longer lifetime in the process than
0b8986
@@ -1252,7 +1255,7 @@
0b8986
     /* Cannot call ERR_free_strings() etc here in case any other code
0b8986
      * in the process using OpenSSL. */
0b8986
 
0b8986
-#ifdef NE_HAVE_TS_SSL
0b8986
+#ifdef WITH_OPENSSL_LOCKING
0b8986
     /* Only unregister the callbacks if some *other* library has not
0b8986
      * come along in the mean-time and trampled over the callbacks
0b8986
      * installed by neon. */