From 93448fea67d371989492be8f5be1adf049365991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Tue, 1 Jan 2013 21:33:46 +0100 Subject: [PATCH] refuse to read and write to the same file --- opustags.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opustags.c b/opustags.c index f6fc851..a5f9bde 100644 --- a/opustags.c +++ b/opustags.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -247,6 +248,15 @@ int main(int argc, char **argv){ return EXIT_FAILURE; } path_in = argv[optind]; + if(path_out != NULL && strcmp(path_in, "-") != 0){ + char canon_in[PATH_MAX+1], canon_out[PATH_MAX+1]; + if(realpath(path_in, canon_in) && realpath(path_out, canon_out)){ + if(strcmp(canon_in, canon_out) == 0){ + fputs("error: the input and output files are the same\n", stderr); + return EXIT_FAILURE; + } + } + } FILE *out = NULL; if(path_out != NULL){ if(strcmp(path_out, "-") == 0)