qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Cc: Yeqi Fu <fufuyqqqqqq@gmail.com>,
	richard.henderson@linaro.org, qemu-devel@nongnu.org,
	Laurent Vivier <laurent@vivier.eu>
Subject: Re: [RFC v2 6/6] linux-user: Add '-native-bypass' option
Date: Mon, 12 Jun 2023 14:06:35 +0100	[thread overview]
Message-ID: <878rco7r3p.fsf@linaro.org> (raw)
In-Reply-To: <vz1az.urjahnph4c90@linaro.org>


Manos Pitsidianakis <manos.pitsidianakis@linaro.org> writes:

> On Wed, 07 Jun 2023 19:47, Yeqi Fu <fufuyqqqqqq@gmail.com> wrote:
>>--- a/linux-user/main.c
>>+++ b/linux-user/main.c
>>+    /* Set the library for native bypass  */
>>+    if (native_lib != NULL) {
>>+        char *token = malloc(strlen(native_lib) + 12);
>
> malloc() can fail (in rare circumstances). Check for the return value
> here. Or use g_malloc() which terminates on alloc failure.

We avoid malloc in favour of g_malloc(). You can use g_try_malloc for
certain cases (although this is not one of them). However you can make
this glibs problem with something like:

    /* Set the library for native bypass  */
    if (native_lib != NULL) {
        GString *lib = g_string_new(native_lib);
        lib = g_string_prepend(lib, "LD_PRELOAD=");
        if (envlist_appendenv(envlist, g_string_free(lib, false), ":") != 0) {
            usage(EXIT_FAILURE);
        }
    }


>
>>+        strcpy(token, "LD_PRELOAD=");
>>+        strcat(token, native_lib);
>
> (You could alternatively use snprintf() here)

We have a section on strings in the developer manual:

 https://qemu.readthedocs.io/en/latest/devel/style.html#string-manipulation

so we have things like pstrcat and pstrcpy. However this isn't criticl
performance path so GString provides a nice memory safe wrapper for all
this sort of manipulation.

<snip>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2023-06-12 13:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 16:47 [RFC v2 0/6] Native Library Calls Yeqi Fu
2023-06-07 16:47 ` [RFC v2 1/6] build: Add configure options for native calls Yeqi Fu
2023-06-09  5:08   ` Manos Pitsidianakis
2023-06-12 11:54   ` Alex Bennée
2023-06-12 13:02     ` Alex Bennée
2023-06-07 16:47 ` [RFC v2 2/6] Add the libnative library Yeqi Fu
2023-06-15  7:59   ` Alex Bennée
2023-06-07 16:47 ` [RFC v2 3/6] target/i386: Add native library calls Yeqi Fu
2023-06-07 19:08   ` Richard Henderson
2023-06-07 19:19   ` Richard Henderson
2023-06-07 16:47 ` [RFC v2 4/6] target/mips: " Yeqi Fu
2023-06-07 19:15   ` Richard Henderson
2023-06-07 16:47 ` [RFC v2 5/6] target/arm: " Yeqi Fu
2023-06-07 16:47 ` [RFC v2 6/6] linux-user: Add '-native-bypass' option Yeqi Fu
2023-06-09  5:24   ` Manos Pitsidianakis
2023-06-12 13:06     ` Alex Bennée [this message]
2023-06-12 13:23   ` Alex Bennée

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=878rco7r3p.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=fufuyqqqqqq@gmail.com \
    --cc=laurent@vivier.eu \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 NNTP newsgroup(s).