From: Bill Parker <wp02855@gmail.com>
To: libffi-discuss@sourceware.org
Subject: Missing sanity checks for various C library function calls...
Date: Mon, 06 Apr 2015 20:48:00 -0000 [thread overview]
Message-ID: <CAFrbyQw14iahHM0k7LPss5CbMusA6-VgKG7pfeae51f86jh+eA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]
Hello All,
In reviewing code for Python-3.4.3 in directory
'Modules/_ctypes/libffi/src/arm', file 'ffi.c', I found a pair
of calls to calloc() which do not test for a return value
of NULL, indicating failure. The patch file below corrects
this issue:
--- ffi.c.orig 2015-04-04 15:43:19.662709073 -0700
+++ ffi.c 2015-04-04 15:51:27.142665269 -0700
@@ -629,12 +629,21 @@
/* We have valid trampoline and config pages */
table = calloc (1, sizeof(ffi_trampoline_table));
+ if (table == NULL) { /* oops, calloc() failed, now what??? */
+ fprintf(stderr, "vm calloc() failure: %d at %s:%d\n", kt,
__FILE__, __LINE__);
+ return NULL; /* go home??? */
+ }
table->free_count = FFI_TRAMPOLINE_COUNT;
table->config_page = config_page;
table->trampoline_page = trampoline_page;
/* Create and initialize the free list */
table->free_list_pool = calloc(FFI_TRAMPOLINE_COUNT,
sizeof(ffi_trampoline_table_entry));
+ if (table->free_list_pool == NULL) { /* oops, calloc() failed, now what */
+ fprintf(stderr, "vm calloc() failure: %d at %s:%d\n", kt,
__FILE__, __LINE__);
+ free(table); /* free table (from previos calloc() call) */
+ return NULL; /* go home??? *
+ }
uint16_t i;
for (i = 0; i < table->free_count; i++) {
I am attaching the patch file to this email
Bill Parker (wp02855 at gmail dot com)
[-- Attachment #2: ffi.c.patch --]
[-- Type: application/octet-stream, Size: 1046 bytes --]
--- ffi.c.orig 2015-04-04 15:43:19.662709073 -0700
+++ ffi.c 2015-04-04 15:51:27.142665269 -0700
@@ -629,12 +629,21 @@
/* We have valid trampoline and config pages */
table = calloc (1, sizeof(ffi_trampoline_table));
+ if (table == NULL) { /* oops, calloc() failed, now what??? */
+ fprintf(stderr, "vm calloc() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
+ return NULL; /* go home??? */
+ }
table->free_count = FFI_TRAMPOLINE_COUNT;
table->config_page = config_page;
table->trampoline_page = trampoline_page;
/* Create and initialize the free list */
table->free_list_pool = calloc(FFI_TRAMPOLINE_COUNT, sizeof(ffi_trampoline_table_entry));
+ if (table->free_list_pool == NULL) { /* oops, calloc() failed, now what */
+ fprintf(stderr, "vm calloc() failure: %d at %s:%d\n", kt, __FILE__, __LINE__);
+ free(table); /* free table (from previos calloc() call) */
+ return NULL; /* go home??? *
+ }
uint16_t i;
for (i = 0; i < table->free_count; i++) {
reply other threads:[~2015-04-06 20:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFrbyQw14iahHM0k7LPss5CbMusA6-VgKG7pfeae51f86jh+eA@mail.gmail.com \
--to=wp02855@gmail.com \
--cc=libffi-discuss@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).