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] [day] [month] [year] [list]
Message-ID: <4f536461-ee2c-73a0-9d28-668a99f8a027@gmail.com>
Date:   Wed, 15 Mar 2023 17:33:40 +0900
From:   Paran Lee <p4ranlee@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Ian Rogers <irogers@...gle.com>,
        Adrian Hunter <adrian.hunter@...el.com>
Cc:     Josh Poimboeuf <jpoimboe@...hat.com>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [RESEND PATCH] perf tools: Add levenshtein ENOMEM check



23. 3. 15. 15:11에 Paran Lee 이(가) 쓴 글:
> The levenshtein algorithm requires exception handling
> when making dynamic allocations strings.

Sorry about that. I modified the code to make it behave incorrectly.

>  	int len1 = strlen(string1), len2 = strlen(string2);
> -	int *row0 = malloc(sizeof(int) * (len2 + 1));
> -	int *row1 = malloc(sizeof(int) * (len2 + 1));
> -	int *row2 = malloc(sizeof(int) * (len2 + 1));
> +	int *rows, *row0, *row1, *row2;
>  	int i, j;
>  
> +	rows = malloc(3 * sizeof(int) * (len2 + 1));
> +	if(!rows)
> +		return -ENOMEM;
> +
> +	row0 = &rows[0];
> +	row1 = &rows[1];
> +	row2 = &rows[2];
> +
>  	for (j = 0; j <= len2; j++)
>  		row1[j] = j * a;
>  	for (i = 0; i < len1; i++) {
> @@ -79,9 +85,7 @@ int levenshtein(const char *string1, const char *string2,
>  	}
>  
>  	i = row1[len2];
> -	free(row0);
> -	free(row1);
> -	free(row2);
> +	free(rows);
>  
>  	return i;
>  }

I'll think about it a bit more and figure out how to patch it up to make
it look better.

BR
Paran Lee

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ