From 0d8819e68f7d05bf2b1937c79fb656f8067b0ade Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Tue, 6 Nov 2012 08:53:38 +0100 Subject: [PATCH] INIT allow iscsi_context = NULL in iscsi_set_error() qemu-kvm calls iscsi_parse_url_full() with iscsi = NULL. In case there is an invalid URL specified qemu-kvm segfaults when it tries to set iscsi->error_string. I tried to patch this in qemu-kvm, but the initiator_name is dirived from the target name so this seemed to be the easier approach. --- lib/init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/init.c b/lib/init.c index cf51500..2fdc3c2 100644 --- a/lib/init.c +++ b/lib/init.c @@ -293,8 +293,13 @@ iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, ...) } va_end(ap); - strncpy(iscsi->error_string,errstr,MAX_STRING_SIZE); - DPRINTF(iscsi,1,"%s",iscsi->error_string); + if (iscsi != NULL) { + strncpy(iscsi->error_string,errstr,MAX_STRING_SIZE); + DPRINTF(iscsi,1,"%s",iscsi->error_string); + } + else { + fprintf(stderr,"libiscsi: %s\n", errstr); + } } void