From nobody Mon Feb 9 23:01:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529376005603166.92122540503033; Mon, 18 Jun 2018 19:40:05 -0700 (PDT) Received: from localhost ([::1]:38696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6Yr-0001Z7-8n for importer@patchew.org; Mon, 18 Jun 2018 22:40:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5iW-00028u-Hi for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5iR-00009l-Ly for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:45:56 -0400 Received: from mail-oi0-x22b.google.com ([2607:f8b0:4003:c06::22b]:34774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5iR-00009Y-Gk; Mon, 18 Jun 2018 21:45:51 -0400 Received: by mail-oi0-x22b.google.com with SMTP id i205-v6so16712249oib.1; Mon, 18 Jun 2018 18:45:51 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id b4-v6sm7200134otf.79.2018.06.18.18.45.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=VprMFyDS392JXPSIMXsRatIG6g9hq/SSPzBns5VJi7o=; b=YCIm8DvWeCEn/3tjz67cKjKwZFD8RC4zlADn0z1RT8H1Ox5A436+e9Y9LEIPoYamyi K2BQJXwnAIvdAFV7ZzM67kl4E//tXO5wtJceu4CHywIKXugMlCdO69AkBLrSB3iBtgKo GEqHmb5c8/NZ0HiLeOKVNp2iza1T8rvclTNLwZz8RAjlyAOxADVCZenE1KJlDraBN59x U75ewtZ8s7foVLC3Q7YBmAvHDaeVZAhfaA6B8yIQzJHy7pLblN8f+deaFcPG41z8N4HJ rxzWX8BuWDbJ4koVK7EpcG0d7gFgiskpkpOxz/i2TkQIECe3qWNpB62DcmvAUJHObc/C 9SEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=VprMFyDS392JXPSIMXsRatIG6g9hq/SSPzBns5VJi7o=; b=icM/Iv6P78zP92HW0rRf0Fhcuc9HSOUxJnq17AjBwMleQETJcB5ut8MuJ3mG+FBR/4 OWd8guW04wxNxJj9UwkJ542ENVspJnoJhe25FejguoiNaTXj5hAEdH7cHE7uLvKcget7 2ktVvFzDVDjYUqbAvg57CzvPuP18cig1VP90r++zgB6xu8Bs33NWArKhOIKt/zVn3BpD XH5MvSA9mT58sqJN5N2xoHJBDd6bI+3GQTdBm6pNXNSYZh8SqpmkrY51ONmcGINLxXCW U+QeOZ6sPuHmvdgvVeQvNXQQYB+ovgNY/qy9MEJxvdlz88Sptpmnsvb0nqrRuWB44LJA 3MGg== X-Gm-Message-State: APt69E0pput6iM21YY9Z66edp4ehNCx6/WPYu4772NtvFSqmCeN1PgVg Mk2wCXnzgY5ssLS75aWxzc6bjPdE X-Google-Smtp-Source: ADUXVKLcC0cJ2he2z/pyMyfCvh9gv7g6zLeOHxqzB3JhQfBM5699SQl9VSjK79HwF67k5oUCzYoZXw== X-Received: by 2002:aca:da82:: with SMTP id r124-v6mr7598479oig.19.1529372750258; Mon, 18 Jun 2018 18:45:50 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:42:14 -0500 Message-Id: <20180619014319.28272-49-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::22b Subject: [Qemu-devel] [PATCH 048/113] block/file-posix: Fix fully preallocated truncate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Max Reitz Storing the lseek() result in an int results in it overflowing when the file is at least 2 GB big. Then, we have a 50 % chance of the result being "negative" and thus thinking an error occurred when actually everything went just fine. So we should use the correct type for storing the result: off_t. Reported-by: Daniel P. Berrange Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1549231 Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20180228131315.30194-2-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz (cherry picked from commit 82b45e0a0b824787bd79ce3f6453eaa2afddd138) Signed-off-by: Michael Roth --- block/file-posix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 36ee89e940..275953fdc6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1694,6 +1694,7 @@ static int raw_regular_truncate(int fd, int64_t offse= t, PreallocMode prealloc, case PREALLOC_MODE_FULL: { int64_t num =3D 0, left =3D offset - current_length; + off_t seek_result; =20 /* * Knowing the final size from the beginning could allow the file @@ -1708,8 +1709,8 @@ static int raw_regular_truncate(int fd, int64_t offse= t, PreallocMode prealloc, =20 buf =3D g_malloc0(65536); =20 - result =3D lseek(fd, current_length, SEEK_SET); - if (result < 0) { + seek_result =3D lseek(fd, current_length, SEEK_SET); + if (seek_result < 0) { result =3D -errno; error_setg_errno(errp, -result, "Failed to seek to the old end of file"); --=20 2.11.0