to repro the segfault:
touch empty && xsel -ib < empty
diff --git x11/xsel/patches/patch-xsel_c x11/xsel/patches/patch-xsel_c
index 0a6b2018bc6..fee17f88664 100644
--- x11/xsel/patches/patch-xsel_c
+++ x11/xsel/patches/patch-xsel_c
@@ -4,8 +4,9 @@ $OpenBSD: patch-xsel_c,v 1.2 2014/07/07 08:25:16 sthen Exp $
- ensure NUM_TARGETS does not exceed MAX_NUM_TARGETS.
- plug a memory leak in handle_targets()
---- xsel.c.orig Mon Jun 30 00:10:19 2014
-+++ xsel.c Mon Jun 30 00:20:50 2014
+Index: xsel.c
+--- xsel.c.orig
++++ xsel.c
@@ -15,6 +15,7 @@
#include "config.h"
#endif
@@ -14,7 +15,24 @@ $OpenBSD: patch-xsel_c,v 1.2 2014/07/07 08:25:16 sthen Exp $
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
-@@ -1300,14 +1301,16 @@ handle_targets (Display * display, Window requestor, A
+@@ -809,6 +810,8 @@ try_read:
+ if (current_alloc == total_input) {
+ if ((d = (current_alloc % insize)) != 0) current_alloc += (insize-d);
+ current_alloc *= 2;
++ /* make sure we have at least one byte, for final \0 */
++ if (!current_alloc) ++current_alloc;
+ new_buffer = realloc (read_buffer, current_alloc);
+ if (new_buffer == NULL) {
+ exit_err ("realloc error");
+@@ -833,6 +836,7 @@ try_read:
+ total_input += n;
+ } while (n != 0 && !fatal);
+
++ assert(total_input < current_alloc);
+ read_buffer[total_input] = '\0';
+
+ print_debug (D_TRACE, "Accumulated %d bytes input", total_input);
+@@ -1300,14 +1304,16 @@ handle_targets (Display * display, Window requestor, A
Atom selection, Time time, MultTrack * mparent)
{
Atom * targets_cpy;
@@ -33,7 +51,7 @@ $OpenBSD: patch-xsel_c,v 1.2 2014/07/07 08:25:16 sthen Exp $
}
/*
-@@ -2078,7 +2081,6 @@ main(int argc, char *argv[])
+@@ -2078,7 +2084,6 @@ main(int argc, char *argv[])
/* Get the NULL atom */
null_atom = XInternAtom (display, "NULL", False);
@@ -41,7 +59,7 @@ $OpenBSD: patch-xsel_c,v 1.2 2014/07/07 08:25:16 sthen Exp $
/* Get the TEXT atom */
text_atom = XInternAtom (display, "TEXT", False);
-@@ -2096,6 +2098,8 @@ main(int argc, char *argv[])
+@@ -2096,6 +2101,8 @@ main(int argc, char *argv[])
supported_targets[s++] = XA_STRING;
NUM_TARGETS++;