From: H.G.Muller Date: Fri, 13 Jan 2017 12:26:44 +0000 (+0100) Subject: Fix usage of memory after free in -replace option X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=4440c1bb156f64d3615f1c1e91ff5fbf2d7d9ca5 Fix usage of memory after free in -replace option The code for implementing the -replace option was using a string after its memory was freed, which might not work in all allocation systems. --- diff --git a/args.h b/args.h index 1da2448..fbdd498 100644 --- a/args.h +++ b/args.h @@ -1186,9 +1186,9 @@ ParseArgs(GetFunc get, void *cl) break; } if(replace) { // previous -replace option makes this string option conditional - char *p = (char*) replace; + int differs = strcmp(*(char**) ad->argLoc, (char*) replace); free(replace); replace = NULL; // but expires in the process - if(strcmp(*(char**) ad->argLoc, p)) break; // only use to replace the given string + if(differs) break; // only use to replace the given string } ASSIGN(*(char **) ad->argLoc, argValue); break;