summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/network-openssl.c20
-rw-r--r--src/fe-common/core/chat-completion.c57
-rw-r--r--src/fe-common/irc/fe-irc-commands.c12
-rwxr-xr-xutils/tap-test20
4 files changed, 101 insertions, 8 deletions
diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index c7ce4b43..9fddf073 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -46,6 +46,7 @@
#endif
/* OpenSSL 1.1.0 also introduced some useful additions to the api */
+#if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined (LIBRESSL_VERSION_NUMBER)
static int X509_STORE_up_ref(X509_STORE *vfy)
{
@@ -57,6 +58,7 @@ static int X509_STORE_up_ref(X509_STORE *vfy)
return (n > 1) ? 1 : 0;
}
#endif
+#endif
/* ssl i/o channel object */
typedef struct
@@ -72,7 +74,10 @@ typedef struct
} GIOSSLChannel;
static int ssl_inited = FALSE;
+/* https://github.com/irssi/irssi/issues/820 */
+#if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
static X509_STORE *store = NULL;
+#endif
static void irssi_ssl_free(GIOChannel *handle)
{
@@ -379,7 +384,9 @@ static GIOFuncs irssi_ssl_channel_funcs = {
gboolean irssi_ssl_init(void)
{
+#if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
int success;
+#endif
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
if (!OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL)) {
@@ -391,6 +398,8 @@ gboolean irssi_ssl_init(void)
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
#endif
+
+#if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
store = X509_STORE_new();
if (store == NULL) {
g_error("Could not initialize OpenSSL: X509_STORE_new() failed");
@@ -404,6 +413,7 @@ gboolean irssi_ssl_init(void)
store = NULL;
/* Don't return an error; the user might have their own cafile/capath. */
}
+#endif
ssl_inited = TRUE;
@@ -522,13 +532,21 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
g_free(scafile);
g_free(scapath);
verify = TRUE;
- } else if (store != NULL) {
+ }
+#if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
+ else if (store != NULL) {
/* Make sure to increment the refcount every time the store is
* used, that's essential not to get it free'd by OpenSSL when
* the SSL_CTX is destroyed. */
X509_STORE_up_ref(store);
SSL_CTX_set_cert_store(ctx, store);
}
+#else
+ else {
+ if (!SSL_CTX_set_default_verify_paths(ctx))
+ g_warning("Could not load default certificates");
+ }
+#endif
if(!(ssl = SSL_new(ctx)))
{
diff --git a/src/fe-common/core/chat-completion.c b/src/fe-common/core/chat-completion.c
index 97cd0565..d610008f 100644
--- a/src/fe-common/core/chat-completion.c
+++ b/src/fe-common/core/chat-completion.c
@@ -173,6 +173,7 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
{
CHANNEL_REC *channel;
int own;
+ g_return_if_fail(nick != NULL);
channel = channel_find(server, target);
if (channel != NULL) {
@@ -185,6 +186,7 @@ static void sig_message_join(SERVER_REC *server, const char *channel,
const char *nick, const char *address)
{
CHANNEL_REC *chanrec;
+ g_return_if_fail(nick != NULL);
chanrec = channel_find(server, channel);
if (chanrec != NULL)
@@ -639,6 +641,59 @@ static void complete_window_nicks(GList **list, WINDOW_REC *window,
}
}
+/* Checks if a line is only nicks from autocompletion.
+ This lets us insert colons only at the beginning of a list
+ of nicks */
+static int only_nicks(const char *linestart)
+{
+ int i = 1;
+ char prev;
+
+ // at the beginning of the line
+ if (*linestart == '\0') {
+ return TRUE;
+ }
+
+ /* completion_char being a whole string introduces loads of edge cases
+ and can't be handled generally. Skip this case; we handled the
+ "beginning of line" case already */
+ if (completion_char[1] != '\0')
+ return FALSE;
+
+ /* This would make the completion char get inserted everywhere otherwise */
+ if (*completion_char == ' ')
+ return FALSE;
+
+ /* First ensure that the line is of the format "foo: bar: baz"
+ we check this by ensuring each space is preceded by a colon or
+ another space */
+ while (linestart[i] != '\0') {
+ if (linestart[i] == ' ') {
+ prev = linestart[i - 1];
+ if (prev != *completion_char && prev != ' ')
+ return FALSE;
+ }
+ i += 1;
+ }
+
+ /* There's an edge case here, if we're completing something
+ like `foo: bar ba<tab>`, then the `linestart` line will end
+ at "bar", and we'll miss the space. Ensure that the end
+ of the line is a colon followed by an optional series of spaces */
+ i -= 1;
+ while (i >= 0) {
+ if (linestart[i] == ' ') {
+ i--;
+ continue;
+ } else if (linestart[i] == *completion_char) {
+ return TRUE;
+ } else {
+ break;
+ }
+ }
+ return FALSE;
+}
+
static void sig_complete_word(GList **list, WINDOW_REC *window,
const char *word, const char *linestart,
int *want_space)
@@ -691,7 +746,7 @@ static void sig_complete_word(GList **list, WINDOW_REC *window,
} else if (channel != NULL) {
/* nick completion .. we could also be completing a nick
after /MSG from nicks in channel */
- const char *suffix = *linestart != '\0' ? NULL : completion_char;
+ const char *suffix = only_nicks(linestart) ? completion_char : NULL;
complete_window_nicks(list, window, word, suffix);
} else if (window->level & MSGLEVEL_MSGS) {
/* msgs window, complete /MSG nicks */
diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c
index 11a911d2..7a6b17a6 100644
--- a/src/fe-common/irc/fe-irc-commands.c
+++ b/src/fe-common/irc/fe-irc-commands.c
@@ -345,16 +345,18 @@ static void cmd_ts(const char *data)
}
typedef struct {
- IRC_SERVER_REC *server;
+ char *server_tag;
char *nick;
} OPER_PASS_REC;
static void cmd_oper_got_pass(const char *password, OPER_PASS_REC *rec)
{
- if (*password != '\0')
- irc_send_cmdv(rec->server, "OPER %s %s", rec->nick, password);
+ SERVER_REC *server_rec = server_find_tag(rec->server_tag);
+ if (*password != '\0' && IS_IRC_SERVER(server_rec))
+ irc_send_cmdv((IRC_SERVER_REC *) server_rec, "OPER %s %s", rec->nick, password);
g_free(rec->nick);
- g_free(rec);
+ g_free(rec->server_tag);
+ g_free(rec);
}
static void cmd_oper(const char *data, IRC_SERVER_REC *server)
@@ -374,7 +376,7 @@ static void cmd_oper(const char *data, IRC_SERVER_REC *server)
OPER_PASS_REC *rec;
rec = g_new(OPER_PASS_REC, 1);
- rec->server = server;
+ rec->server_tag = g_strdup(server->tag);
rec->nick = g_strdup(*nick != '\0' ? nick : server->nick);
format = format_get_text(MODULE_NAME, NULL, server, NULL,
diff --git a/utils/tap-test b/utils/tap-test
index 481e333e..b3ef8b04 100755
--- a/utils/tap-test
+++ b/utils/tap-test
@@ -2,4 +2,22 @@
# run a GTest in tap mode. The test binary is passed as $1
-$1 -k --tap
+t="$1"; shift
+if ${PKG_CONFIG:-pkg-config} --atleast-version 2.40 glib-2.0; then
+exec "$t" -k --tap "$@"
+else # GTest does not support tap yet
+ (((("$t" "$@"; echo $? >&3) | ${AM_TAP_AWK:-awk} '
+{
+ if (/: /) {
+ i++
+ ok = /: OK/
+ sub(/:/, " #")
+ print (ok ? "ok " : "not ok ") i " " $0
+ } else {
+ print "# " $0
+ }
+} END {
+ print 1 ".." i
+}
+' >&4) 3>&1) | (read xs; exit $xs)) 4>&1
+fi