lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YKURoStYXwQ3FnxI@krava>
Date:   Wed, 19 May 2021 15:24:49 +0200
From:   Jiri Olsa <jolsa@...hat.com>
To:     Denys Zagorui <dzagorui@...co.com>
Cc:     linux-kernel@...r.kernel.org, peterz@...radead.org,
        mingo@...hat.com, acme@...nel.org, mark.rutland@....com,
        alexander.shishkin@...ux.intel.com, namhyung@...nel.org
Subject: Re: [PATCH v5 1/3] perf report: compile tips.txt in perf binary

On Mon, May 17, 2021 at 01:46:02AM -0700, Denys Zagorui wrote:

SNIP

>  	return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
>  }
>  
> +#define MAX_TIPS        60
> +
> +static const char *perf_tip(void)
> +{
> +	char *str[MAX_TIPS];
> +	int i = 0;
> +
> +	_binary_Documentation_tips_txt_start[_binary_Documentation_tips_txt_end -
> +		_binary_Documentation_tips_txt_start - 1] = 0;
> +
> +	str[i] = strtok(_binary_Documentation_tips_txt_start, "\n");
> +	if (!str[i])
> +		return "Tips cannot be found!";
> +
> +	i++;
> +
> +	while (i < MAX_TIPS) {
> +		str[i] = strtok(NULL, "\n");
> +		if (!str[i])
> +			break;
> +		i++;
> +	}
> +
> +	return str[random() % i];

that still does not solve that we set MAX_TIPS and have
no way of checking that's still valid

how about something like below (completely untested):


static const char *perf_tip(void)
{
       char *start = _binary_Documentation_tips_txt_start;
       char *tok, *tmp, *prev;
       int pick, size;

       size = _binary_Documentation_tips_txt_end - start;
       pick = random() % size;

       _binary_Documentation_tips_txt_start[size - 1] = 0;

       for (tok = strtok_r(start, "\n", &tmp); tok;
            tok = strtok_r(NULL, "\n", &tmp)) {
               if (pick < (tok - start))
                       return prev;
               prev = tok;
       }

       return prev;
}

this way you wouldn't need array with MAX_TIPS defined

jirka

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ