From 5dbd1c96106aa09d5d40f2ee4fc8b543ffe50e8a Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Fri, 26 Sep 2014 20:25:06 +0900 Subject: [PATCH] Adding safe-setenv alternative to setenv to workaround shellshock bug. --- lib/chibi/ast.scm | 13 +++++++++++++ lib/chibi/ast.sld | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/chibi/ast.scm b/lib/chibi/ast.scm index 32a049ff..81c62bf9 100644 --- a/lib/chibi/ast.scm +++ b/lib/chibi/ast.scm @@ -356,6 +356,19 @@ ;;> Returns the first string cursor of \var{pat} in \var{str}, ;;> of \scheme{#f} if it's not found. +;;> \procedure{(safe-setenv name value)} + +;;> Equivalent to \scheme{setenv} but does nothing and returns +;;> \scheme{#f} if \var{value} is a function definition. Used to +;;> circumvent the vulnerability of the shellshock bug. + +(define (safe-setenv name value) + (define (function-def? str) + (and (> (string-size value) 5) + (equal? "() {" (substring value 0 4)))) + (and (not (function-def? value)) + (setenv name value))) + ;;> \procedure{(atomically expr)} ;;> Run \var{expr} atomically, disabling yields. Ideally should only be diff --git a/lib/chibi/ast.sld b/lib/chibi/ast.sld index c9356be1..2ce1a223 100644 --- a/lib/chibi/ast.sld +++ b/lib/chibi/ast.sld @@ -36,7 +36,7 @@ type-name type-cpl type-parent type-slots type-num-slots type-printer object-size integer->immediate gc atomically thread-list string-contains errno integer->error-string - flatten-dot update-free-vars! setenv unsetenv) + flatten-dot update-free-vars! setenv unsetenv safe-setenv) (import (chibi)) (include-shared "ast") (include "ast.scm"))