Fix (mkstemp! "XX" 0) errors
authorAndy Wingo <wingo@pobox.com>
Wed, 1 Mar 2017 13:48:37 +0000 (14:48 +0100)
committerAndy Wingo <wingo@pobox.com>
Wed, 1 Mar 2017 13:48:37 +0000 (14:48 +0100)
* libguile/filesys.c (scm_i_mkstemp): Validate "mode" argument as a
  string, and validate writability of template string early too.  Thanks
  to Jean Louis for the bug report.

libguile/filesys.c

index 40d5a41d3da07940aee6cf18c268201bdaa846e8..b5b7e723b51e8302b328a23c2ec05ac1545db392 100644 (file)
@@ -1475,6 +1475,14 @@ SCM_DEFINE (scm_i_mkstemp, "mkstemp!", 1, 1, 0,
   int open_flags, is_binary;
   SCM port;
 
+  SCM_VALIDATE_STRING (SCM_ARG1, tmpl);
+  if (!SCM_UNBNDP (mode))
+    SCM_VALIDATE_STRING (SCM_ARG2, mode);
+
+  /* Ensure tmpl is mutable.  */
+  scm_i_string_start_writing (tmpl);
+  scm_i_string_stop_writing ();
+
   scm_dynwind_begin (0);
 
   c_tmpl = scm_to_locale_string (tmpl);