Blame SOURCES/kvm-curl-Handle-failure-for-potentially-large-allocation.patch

9ae3a8
From e7ec271f6886eb7c37e200309d677a0f4dc32efe Mon Sep 17 00:00:00 2001
9ae3a8
From: Richard Jones <rjones@redhat.com>
9ae3a8
Date: Thu, 11 Jun 2015 11:40:24 +0200
9ae3a8
Subject: [PATCH 24/30] curl: Handle failure for potentially large allocations
9ae3a8
9ae3a8
Message-id: <1434022828-13037-18-git-send-email-rjones@redhat.com>
9ae3a8
Patchwork-id: 65852
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm v3 PATCH 17/21] curl: Handle failure for potentially large allocations
9ae3a8
Bugzilla: 1226684
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
Some code in the block layer makes potentially huge allocations. Failure
9ae3a8
is not completely unexpected there, so avoid aborting qemu and handle
9ae3a8
out-of-memory situations gracefully.
9ae3a8
9ae3a8
This patch addresses the allocations in the curl block driver.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
Reviewed-by: Benoit Canet <benoit@irqsave.net>
9ae3a8
9ae3a8
Upstream-status: 8dc7a7725bd6db2aa7e3c09b49bc21a1a25f40cb
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/curl.c | 8 +++++++-
9ae3a8
 1 file changed, 7 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/block/curl.c b/block/curl.c
9ae3a8
index d95789a..2486449 100644
9ae3a8
--- a/block/curl.c
9ae3a8
+++ b/block/curl.c
9ae3a8
@@ -618,7 +618,13 @@ static void curl_readv_bh_cb(void *p)
9ae3a8
     state->buf_start = start;
9ae3a8
     state->buf_len = acb->end + s->readahead_size;
9ae3a8
     end = MIN(start + state->buf_len, s->len) - 1;
9ae3a8
-    state->orig_buf = g_malloc(state->buf_len);
9ae3a8
+    state->orig_buf = g_try_malloc(state->buf_len);
9ae3a8
+    if (state->buf_len && state->orig_buf == NULL) {
9ae3a8
+        curl_clean_state(state);
9ae3a8
+        acb->common.cb(acb->common.opaque, -ENOMEM);
9ae3a8
+        qemu_aio_release(acb);
9ae3a8
+        return;
9ae3a8
+    }
9ae3a8
     state->acb[0] = acb;
9ae3a8
 
9ae3a8
     snprintf(state->range, 127, "%zd-%zd", start, end);
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8