Bug #31

jam.exe crashes when attempting to write to a file stream which failed to open

Added by Steven Craft over 9 years ago. Updated almost 9 years ago.

Status:NewStart date:10/04/2010
Priority:NormalDue date:
Assignee:Joshua Jensen% Done:


Target version:-


For the case in question, the crash occurs in: command.c, in the function cmd_string, around line 317 there is a call to fopen:

file = fopen(buffer_ptr( &subbuff ), "wb");

This call has just failed for me, the reason being the file it is trying to open is something like:


But this path is simply to long, the folder exists but a filename of that length can not be created in that folder (I tried manually creating it but Windows does not let me me).

The validity of the file pointer isn't checked, which leads to a crash on around line 352 where it attempts to write to the file stream:

fwrite(buffer_ptr( &subbuff2 ), 1, expandedSize - 1, file);

I appreciate the only fix I'm going to be able to do is make my path shorter, but it would be beneficial if jam.exe could relay this information back to the end user instead of crashing.


#1 Updated by Leander Hasty almost 9 years ago

Since we just ran into this trying to write a file to a non-existent directory, here's a patch of sorts against jamplus-101231-src.zip, generated in the jamplus dir (with TortoiseUDiff, so apologies if it doesn't apply cleanly):

Index: src/command.c
--- src/command.c
+++ src/command.c
@@ -315,6 +315,10 @@
             ((char*)ine)[0] = save;

             file = fopen(buffer_ptr( &subbuff ), "wb");
+            if ( file == 0 ) {
+                printf( "jam: errno %u, trying to fopen %s\n", errno, buffer_ptr( &subbuff ) );
+                exit(EXITBAD);
+            }
             buffer_free( &subbuff );


Also available in: Atom PDF