From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86237 invoked by alias); 13 Mar 2015 18:01:50 -0000 Mailing-List: contact jit-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: Sender: jit-owner@gcc.gnu.org Received: (qmail 86213 invoked by uid 89); 13 Mar 2015 18:01:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.98.6 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Message-ID: <1426269343.8624.206.camel@surprise> Subject: Re: [PATCH, jit]: Robustify vasprintf error checks From: David Malcolm To: Uros Bizjak Cc: jit@gcc.gnu.org, "gcc-patches@gcc.gnu.org" Date: Thu, 01 Jan 2015 00:00:00 -0000 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-SW-Source: 2015-q1/txt/msg00072.txt.bz2 On Fri, 2015-03-13 at 17:53 +0100, Uros Bizjak wrote: > Hello! > > As documented in [1] asprintf and vasprintf return: > > --quote-- > Return value: > > Both functions set *ret to be a pointer to a malloc()'d buffer > sufficiently large to hold the formatted string. This pointer should > be passed to free() to release the allocated storage when it is no > longer needed. > > The integer value returned by these functions is the number of > characters that were output to the newly allocated string (excluding > the final '\0'). To put it differently, the return value will match > that of strlen(*ret). > > Upon failure, the returned value will be -1, and *ret will be set to NULL. > > Note: Upon failure, other implementations may forget to set *ret and > leave it in an undefined state. Some other implementations may always > set *ret upon failure but forget to assign -1 for the return value in > some edge cases. > --/quote-- > > Based on the note above, the attached patch robustifies vasprintf > return value checks in jit/jit-recording.c. Actually, the same checks > are already implemented in function oprint, around line 1655 in > gengtype.c. > 2015-02-25 Uros Bizjak > > * jit-recording.c (dump::write): Also check vasprintf return value. > (recording::context::add_error_va): Ditto. > (recording::string::from_printf): Ditto. > > The patch was bootstrapped and regression tested on x86_64-linux-gnu. > > OK for mainline? Thanks. I assume that we can rely that any vasprintf implementation manages on failure to at least either write NULL to *ret or to return -1, even if some of them fail to do both? OK for trunk. > > [1] http://asprintf.insanecoding.org/ > > Uros.