[CWB] Patch for faulty open_temporary_file() - fixes external sort and similar tmp file errors

Jan Jona Javorsek jona.javorsek at ijs.si
Tue Oct 8 15:22:05 CEST 2013


Dear all,

I have found out that cqp in recent versions fails when external sort
(as enabled by set ExternalSort on) and probably other such operations
since it fails to open the temporary file properly.

The problem is a small error in the security fix (@149 andrewhard) where
the PID is prepended, generating paths of the form 23423./tmp/cqp.34234.
This results in the following error:
CQP Error:
    Couldn't create temporary file for external sort (aborted).

Following is a simple patch that solves the problem, changing the form
23423./tmp/cqp.34234 into /tmp/cqp.34234.23423. Since andrewhard's
comment  says "Temporary files have the prefix "$PID.cqpt."  that should
perhaps be adjusted as well.

(I am quite amazed that nobody was struck by this problem so far.)

Thank you.

Best,
-jan


Index: cqp/output.c
===================================================================
--- cqp/output.c    (revision 436)
+++ cqp/output.c    (working copy)
@@ -145,7 +145,7 @@
     if (fd)
       fclose(fd);
     intermed_buffer = tempnam(TEMPDIR_PATH, "cqpt."); /* we need to
catch the pointer in order to free it below */
-    sprintf(tmp_name_buffer, "%d.%s", (int)getpid(), intermed_buffer);
+    sprintf(tmp_name_buffer, "%s.%d", intermed_buffer, (int)getpid());
     cl_free(intermed_buffer);
   } while (NULL != (fd = fopen(tmp_name_buffer, "r")));



More information about the CWB mailing list