From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id 6CA933858D38 for ; Wed, 12 Aug 2020 19:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6CA933858D38 Received: by mail-qt1-x843.google.com with SMTP id s16so2392599qtn.7 for ; Wed, 12 Aug 2020 12:17:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NgwxVhWsWgQfWAJAkv8zKuXjjMWIt8QnkfwURh3QTgI=; b=ZFjFTiykAm6tEeKCjr50w4lmkpQpOdxiB3o0YWly8YvOOimBjhguoxwpxAO9IvOr71 8ergdGKQqQvUha2bv9V47BR/SEs2SLrowpXouiKwBLiyM/cmURTd5gZF97dYo+SfQHBH UQqyDZkHD3D3y0KGXTaIcnqCNYkxVMv4tcmo4Y0Mc8TQc7FiRY+dhMOMFp1RKrN+lXxJ ahbEqVeJq6/xaQTn9gKicD4XFCTOfnIhyGEaqjbqfHNeaswWhSRsdNkNVNFE6i19Q8JB Jk5owdvZZwNn4JlazGUwH2eqrSRbo5t55WNzAPCp2UZ4loqP7v6xzlF8Usdgujpqvjxx 3xSg== X-Gm-Message-State: AOAM530/FxnRYdgdA8mpPGSOpvHjZl0nZUNGy69xcOclTSMKKfWt8rri X/U86aexc8/JSNd3v5U3bH4V2J17RfU= X-Google-Smtp-Source: ABdhPJwo+TNOt1Y6jjP+Rutpkk9KK49xKcmbeW2bYKZAYVJsvz9E1vbLyK95l70gw/TrvS4cw5CaVA== X-Received: by 2002:ac8:1349:: with SMTP id f9mr1364153qtj.24.1597259867755; Wed, 12 Aug 2020 12:17:47 -0700 (PDT) Received: from localhost.localdomain ([2804:7f0:8283:9c50:2485:8bda:7d2b:129a]) by smtp.gmail.com with ESMTPSA id a6sm3266318qka.5.2020.08.12.12.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 12:17:47 -0700 (PDT) From: Luis Machado To: gdb-patches@sourceware.org Subject: [PATCH] Fix malloc allocation size sanity check Date: Wed, 12 Aug 2020 16:17:41 -0300 Message-Id: <20200812191741.4220-1-luis.machado@linaro.org> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Aug 2020 19:17:49 -0000 During debugging of PR26362, it was noticed that the malloc size check in check_type_length_before_alloc wasn't detecting an allocation attempt of a huge amount of bytes, making GDB run into an internal error. This happens because we're using an int to store a type's length. When the type length is large enough, the int will overflow and the max_value_size check won't work anymore. The following patch fixes this by making the length variable a size_t. Printing statements were also updated to show the correct number of bytes. gdb/ChangeLog: YYYY-MM-DD Luis Machado * value.c (check_type_length_before_alloc): Use size_t to store a type's length. Use %s and pulongest to print the length. --- gdb/value.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index aac9baaaf5..4efd75fa25 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -997,16 +997,16 @@ show_max_value_size (struct ui_file *file, int from_tty, static void check_type_length_before_alloc (const struct type *type) { - unsigned int length = TYPE_LENGTH (type); + size_t length = TYPE_LENGTH (type); if (max_value_size > -1 && length > max_value_size) { if (type->name () != NULL) - error (_("value of type `%s' requires %u bytes, which is more " - "than max-value-size"), type->name (), length); + error (_("value of type `%s' requires %s bytes, which is more " + "than max-value-size"), type->name (), pulongest (length)); else - error (_("value requires %u bytes, which is more than " - "max-value-size"), length); + error (_("value requires %s bytes, which is more than " + "max-value-size"), pulongest (length)); } } -- 2.17.1