yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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