Skip to content

Commit 2be2b1c

Browse files
authored
scm_p_require: add missing GC protection for a local variable (#21)
Fixes #20. Original code, when SCM_COMPAT_SIOD was enabled, allowed the `filename` object to be freed by GC during the call to `scm_require_internal`, causing a use-after-free problem. This was caused by the C compiler not saving the `filename` pointer on the stack across the call. This patch fixes it by marking `filename` volatile. (I can think of many ways to fix the problem. I chose `volatile` because it's simple and it's already used elsewhere in the codebase)
1 parent 1040016 commit 2be2b1c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/module-sscm-ext.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,19 @@ scm_require_internal(const char *filename)
233233
}
234234

235235
SCM_EXPORT ScmObj
236-
scm_p_require(ScmObj filename)
236+
scm_p_require(volatile ScmObj filename)
237237
{
238238
#if SCM_COMPAT_SIOD
239239
ScmObj loaded_str, retsym;
240240
#endif
241-
const char *c_filename;
242-
243241
DECLARE_FUNCTION("require", procedure_fixed_1);
244242

245243
ENSURE_STRING(filename);
246244

247-
c_filename = SCM_STRING_STR(filename);
248-
scm_require_internal(c_filename);
245+
scm_require_internal(SCM_STRING_STR(filename));
249246

250247
#if SCM_COMPAT_SIOD
251-
loaded_str = make_loaded_str(c_filenam);
248+
loaded_str = make_loaded_str(SCM_STRING_STR(filename));
252249
retsym = scm_intern(SCM_STRING_STR(loaded_str));
253250
SCM_SYMBOL_SET_VCELL(retsym, SCM_TRUE);
254251

0 commit comments

Comments
 (0)