From b6ef430541de83d0adf4378ba2d814a1136c9d68 Mon Sep 17 00:00:00 2001 From: Gabor Melis Date: Mon, 20 Oct 2008 12:05:21 +0000 Subject: [PATCH] 1.0.21.33: fix lack of null termination bug in mk{d,s}temp --- NEWS | 1 + contrib/sb-posix/interface.lisp | 6 ++++-- contrib/sb-posix/posix-tests.lisp | 22 ++++++++++++++++++++++ version.lisp-expr | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index cca4c0b..8d4ed00 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,7 @@ changes in sbcl-1.0.22 relative to 1.0.21: Snellman) * bug fix: on x86 and x86-64 backtraces were sometimes truncated after alien stack frames. + * bug fix: strings passed to mk{s,d}temp lacked null termination changes in sbcl-1.0.21 relative to 1.0.20: * new feature: the compiler is able to track the effective type of a diff --git a/contrib/sb-posix/interface.lisp b/contrib/sb-posix/interface.lisp index c111e76..1da9d8f 100644 --- a/contrib/sb-posix/interface.lisp +++ b/contrib/sb-posix/interface.lisp @@ -169,7 +169,8 @@ (let* ((external-format sb-alien::*default-c-string-external-format*) (arg (sb-ext:string-to-octets (filename template) - :external-format external-format))) + :external-format external-format + :null-terminate t))) (sb-sys:with-pinned-objects (arg) ;; accommodate for the call-by-reference ;; nature of mks/dtemp's template strings. @@ -181,7 +182,8 @@ ;; FIXME: We'd rather return pathnames, but other ;; SB-POSIX functions like this return strings... (let ((pathname (sb-ext:octets-to-string - arg :external-format external-format))) + arg :external-format external-format + :end (1- (length arg))))) ,(if values '(values result pathname) 'pathname)))))) diff --git a/contrib/sb-posix/posix-tests.lisp b/contrib/sb-posix/posix-tests.lisp index 92fef5f..2a97c4c 100644 --- a/contrib/sb-posix/posix-tests.lisp +++ b/contrib/sb-posix/posix-tests.lisp @@ -792,3 +792,25 @@ (values (equal "mktemp" (pathname-name pathname)) (not (equal "XXXXXX" (pathname-type pathname))))) t t) + +#-win32 +(deftest mkstemp.null-terminate + (let* ((default (make-pathname :directory '(:absolute "tmp"))) + (filename (namestring (make-pathname :name "mkstemp-1" + :type "XXXXXX" + :defaults default))) + ;; The magic 64 is the filename length that happens to + ;; trigger the no null termination bug at least on my + ;; machine on a certain build. + (n (- 64 (length (sb-ext:string-to-octets filename))))) + (multiple-value-bind (fd temp) + (sb-posix:mkstemp (make-pathname + :name "mkstemp-1" + :type (format nil "~AXXXXXX" + (make-string n :initial-element #\x)) + :defaults default)) + (let ((pathname (sb-ext:parse-native-namestring temp))) + (unwind-protect + (values (integerp fd) (pathname-name pathname)) + (delete-file temp))))) + t "mkstemp-1") diff --git a/version.lisp-expr b/version.lisp-expr index 8bf7b66..dd190d7 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; checkins which aren't released. (And occasionally for internal ;;; versions, especially for internal versions off the main CVS ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".) -"1.0.21.32" +"1.0.21.33" -- 1.7.10.4