From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33453 invoked by alias); 27 Dec 2016 11:41:29 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 33438 invoked by uid 89); 27 Dec 2016 11:41:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=BAYES_20,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=glibc_tunables, GLIBC_TUNABLES, ALIGN_UP, min_strlen X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Subject: Re: [PATCH 2/4] Initialize tunable list with the GLIBC_TUNABLES environment variable To: Siddhesh Poyarekar , libc-alpha@sourceware.org References: <1479285306-11684-1-git-send-email-siddhesh@sourceware.org> <1479285306-11684-3-git-send-email-siddhesh@sourceware.org> Cc: carlos@redhat.com, adhemerval.zanella@linaro.org From: Florian Weimer Message-ID: <21052a79-a9ba-879c-129a-197fb584e178@redhat.com> Date: Tue, 27 Dec 2016 11:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1479285306-11684-3-git-send-email-siddhesh@sourceware.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2016-12/txt/msg00975.txt.bz2 On 11/16/2016 09:35 AM, Siddhesh Poyarekar wrote: > diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c > +static char * > +tunables_strdup (const char *in) > +{ > + size_t i = 0; > + > + while (in[i++]); Please use an explicit comparison against '\0'. > + char *out = __mmap (NULL, ALIGN_UP (i, __getpagesize ()), > + PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, > + 0); > + > + if (out == MAP_FAILED) > + return NULL; See my initial mail. errno and __getpagesize are not available at this point. > +static size_t > +min_strlen (const char *s) > +{ > + size_t i = 0; > + while (*s++ != '\0') > + i++; > + > + return i; > +} Is there anything which ensures that GCC does not replace this implementation with strlen? > /* Disable a tunable if it is set. */ > static void > disable_tunable (tunable_id_t id, char **envp) > @@ -216,6 +318,23 @@ disable_tunable (tunable_id_t id, char **envp) > > if (env_alias) > tunables_unsetenv (envp, tunable_list[id].env_alias); > + > + char *tunable = getenv (GLIBC_TUNABLES); > + const char *cmp = tunable_list[id].name; > + const size_t len = min_strlen (cmp); > + > + while (tunable && *tunable != '\0' && *tunable != ':') > + { > + if (is_name (tunable, cmp)) > + { > + tunable += len; > + /* Overwrite the = and the value with colons. */ > + while (*tunable != '\0' && *tunable != ':') > + *tunable++ = ':'; > + break; > + } > + tunable++; > + } > } This assumes that the process environment is not mapped read-only. I'm not sure if this is guaranteed by the ABI. Thanks, Florian