From 4440c1bb156f64d3615f1c1e91ff5fbf2d7d9ca5 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Fri, 13 Jan 2017 13:26:44 +0100 Subject: [PATCH] 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. --- args.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) 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; -- 1.7.0.4