write-ups-challenges-2021-2022/restrictive-racket/challenge.rkt

41 lines
1.2 KiB
Racket
Raw Normal View History

2021-12-02 23:33:26 +00:00
#lang racket
(require racket/format)
(provide make-challenge add-status (struct-out challenge))
(struct challenge (id description flag input output allowed status err))
; This list is non-exhaustive, you can help by expanding it.
(define never-allow '(read string->symbol))
(define (verify-allowed allowed)
(define res
(map (lambda (sym)
(define found (member sym never-allow))
(if found
(car found)
'()))
allowed))
(flatten res))
(define (make-challenge id description flag input output allowed)
(define bad-allowed (verify-allowed allowed))
(cond
((not (null? bad-allowed))
(error "Error: you allowed a variable in a challenge that may lead to remote code execution: " (~v bad-allowed)))
((not (= (length input) (length output)))
(error "Input and output of a challenge needs to be of the same length"))
(else
(challenge id description flag input output allowed #f ""))))
(define (add-status status err c)
(challenge (challenge-id c)
(challenge-description c)
(challenge-flag c)
(challenge-input c)
(challenge-output c)
(challenge-allowed c)
status
err))