From 4f9b2de5a5c313a1a50057bde3ce2eb70933b3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 23 Apr 2022 17:41:54 +0200 Subject: [PATCH] Remove use of tempnam function and fix bug (bad check of rename return) --- utils/adept_remove.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/adept_remove.cpp b/utils/adept_remove.cpp index 556e409..a56f6b0 100644 --- a/utils/adept_remove.cpp +++ b/utils/adept_remove.cpp @@ -114,16 +114,16 @@ public: // Use temp file for PDF if (type == gourou::DRMProcessor::ITEM_TYPE::PDF) { - char* tempFile = tempnam("/tmp", NULL); - processor.removeDRM(inputFile, tempFile, type, encryptionKey, encryptionKeySize); + std::string tempFile = filename + ".tmp"; + /* Be sure there is not already a temp file */ + unlink(tempFile.c_str()); + processor.removeDRM(filename, tempFile, type, encryptionKey, encryptionKeySize); /* Original file must be removed before doing a copy... */ - unlink(inputFile); - if (!rename(tempFile, filename.c_str())) + unlink(filename.c_str()); + if (rename(tempFile.c_str(), filename.c_str())) { - free(tempFile); EXCEPTION(gourou::DRM_FILE_ERROR, "Unable to copy " << tempFile << " into " << filename); } - free(tempFile); } else processor.removeDRM(inputFile, filename, type, encryptionKey, encryptionKeySize);