FWIW, if you prefer, rather than the patch attached earlier, this is how
upstream did it:
commit c760ace62ac4fe1cf65d88475d5939c1aa360d6b
Author: Anton Lindqvist <[email protected]>
Date: Thu Aug 25 21:06:44 2016 +0200
Fix segfault when stdin is empty
When reading input from stdin, ensure the initial read buffer capacity
is greater than zero. This prevents the program from crashing when
writing the null terminator to the buffer in read_input.
diff --git a/xsel.c b/xsel.c
index f5a499a..1fc07bf 100644
--- a/xsel.c
+++ b/xsel.c
@@ -949,7 +949,7 @@ initialise_read (unsigned char * read_buffer)
int insize = in_statbuf.st_blksize;
unsigned char * new_buffer = NULL;
- if (S_ISREG (in_statbuf.st_mode)) {
+ if (S_ISREG (in_statbuf.st_mode) && in_statbuf.st_size > 0) {
current_alloc += in_statbuf.st_size;
} else {
current_alloc += insize;
On 3/20/21 7:44 PM, Brennan Vincent wrote:
to repro the segfault:
touch empty && xsel -ib < empty