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]
Date:   Fri, 8 Sep 2017 15:25:14 -0400
From:   Steven Rostedt <rostedt@...dmis.org>
To:     Tom Zanussi <tom.zanussi@...ux.intel.com>
Cc:     tglx@...utronix.de, mhiramat@...nel.org, namhyung@...nel.org,
        vedang.patel@...el.com, bigeasy@...utronix.de,
        joel.opensrc@...il.com, joelaf@...gle.com,
        mathieu.desnoyers@...icios.com, baohong.liu@...el.com,
        linux-kernel@...r.kernel.org, linux-rt-users@...r.kernel.org
Subject: Re: [PATCH v2 34/40] tracing: Add 'last error' error facility for
 hist triggers

On Tue,  5 Sep 2017 16:57:46 -0500
Tom Zanussi <tom.zanussi@...ux.intel.com> wrote:

> +static char *hist_err_str;
> +static char *last_hist_cmd;
> +
> +static int hist_err_alloc(void)
> +{
> +	int ret = 0;
> +
> +	last_hist_cmd = kzalloc(MAX_FILTER_STR_VAL, GFP_KERNEL);
> +	if (!last_hist_cmd)
> +		return -ENOMEM;
> +
> +	hist_err_str = kzalloc(MAX_FILTER_STR_VAL, GFP_KERNEL);
> +	if (!hist_err_str) {
> +		kfree(last_hist_cmd);
> +		ret = -ENOMEM;
> +	}

This gets allocated during boot up. Why have it be allocated in the
first place? Just have it be strings:

static char hist_err_str[MAX_FILTER_STR_VAL];
static char last_hist_cmd[MAX_FILTER_STR_VAL];

You are not saving any space by doing it this way. In fact, you waste
it because now you need to add the pointers to the strings.

> +
> +	return ret;
> +}
> +
> +static void last_cmd_set(char *str)
> +{
> +	if (!last_hist_cmd || !str)
> +		return;
> +
> +	if (strlen(str) > MAX_FILTER_STR_VAL - 1)
> +		return;

Instead of returning nothing, why not just truncate it?

> +
> +	strcpy(last_hist_cmd, str);

	strncpy(last_hist_cmd, str, MAX_FILTER_STR_VAL - 1);
	last_hist_cmd[MAX_FILTER_STR_VAL - 1] = 0;

> +}
> +
> +static void hist_err(char *str, char *var)
> +{
> +	int maxlen = MAX_FILTER_STR_VAL - 1;
> +
> +	if (!hist_err_str || !str)
> +		return;
> +
> +	if (strlen(hist_err_str))
> +		return;
> +
> +	if (!var)
> +		var = "";
> +
> +	if (strlen(hist_err_str) + strlen(str) + strlen(var) > maxlen)
> +		return;
> +
> +	strcat(hist_err_str, str);
> +	strcat(hist_err_str, var);
> +}
> +
> +static void hist_err_event(char *str, char *system, char *event, char *var)
> +{
> +	char err[MAX_FILTER_STR_VAL];
> +
> +	if (system && var)
> +		sprintf(err, "%s.%s.%s", system, event, var);
> +	else if (system)
> +		sprintf(err, "%s.%s", system, event);
> +	else
> +		strcpy(err, var);

Use snprintf() and strncpy() for the above.

-- Steve

> +
> +	hist_err(str, err);
> +}
> +
> +static void hist_err_clear(void)
> +{
> +	if (!hist_err_str)
> +		return;
> +
> +	hist_err_str[0] = '\0';
> +}
> +
> +static bool have_hist_err(void)
> +{
> +	if (hist_err_str && strlen(hist_err_str))
> +		return true;
> +
> +	return false;
> +}
> +

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ