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

Stefan Evert stefanML at collocations.de
Tue Oct 15 16:43:40 CEST 2013


Dear Jan,

thanks for the bug report.  I suppose no one has noticed this because external sorting has been deprecated (or at least very strongly discouraged) for the last ten years or so.  For example, this is what happens on my MacBook if I try an external sort (after fixing the tempname bug):

> sh: gawk: command not found
> sort: string comparison failed: Illegal byte sequence
> sort: Set LC_ALL='C' to work around the problem.
> sort: The strings compared were ` weitere abr\374stungsvertr\344ge \tweitere Abr\374stungsvertr\344ge ' and ` politische zusammenarbeit \tpolitische Zusammenarbeit '.
> CQP Error:
> 	External sort failed (reset to default ordering).
> Information:
> 	Query result sorted in 0.179 seconds


Nonetheless, I've applied a slightly different bug fix to the SVN trunk, which is what I believe Andrew had in mind:

>   sprintf(prefix, "cqpt.%d", (unsigned int)getpid()); /* "cqpt.$$" */
>   tempfile_name = tempnam(TEMPDIR_PATH, prefix); /* string is allocated by tempnam(), needs to be free'd below */
>   if (strlen(tempfile_name) >= TEMP_FILENAME_BUFSIZE) {
>     perror("open_temporary_file(): filename too long for buffer");
>     cl_free(tempfile_name);
>     return NULL;
>   }
>   else {
>     strcpy(tmp_name_buffer, tempfile_name);
>     cl_free(tempfile_name);
>   }
> 



Cheers,
Stefan


On 8 Oct 2013, at 15:22, Jan Jona Javorsek <jona.javorsek at ijs.si> wrote:

> 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



More information about the CWB mailing list