From 1f91d7313019d2dd62800e85881ab7c9ca595903 Mon Sep 17 00:00:00 2001
From: swym <0xfd000000@gmail.com>
Date: Fri, 23 Aug 2019 16:45:11 +0200
Subject: [PATCH] fix(pycardium): make it work with absolute paths

Otherwise, /card10.bin would be writable :)
---
 pycardium/modules/os.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/pycardium/modules/os.c b/pycardium/modules/os.c
index 0bbfc05c..874a0693 100644
--- a/pycardium/modules/os.c
+++ b/pycardium/modules/os.c
@@ -10,12 +10,20 @@
 
 #include "os.h"
 
-bool pycrd_filename_restricted(const char *fname)
+bool pycrd_filename_restricted(const char *path)
 {
 	// files that cannot be opened in write modes
 	const char *const forbidden_files[] = {
 		"card10.bin", "menu.py", "main.py", "card10.cfg"
 	};
+
+	const char *fname = strchr(path, '/');
+	while (fname) {
+		path  = fname + 1;
+		fname = strchr(path, '/');
+	}
+	fname = path;
+
 	for (int i = 0;
 	     i < sizeof(forbidden_files) / sizeof(forbidden_files[0]);
 	     i++) {
-- 
GitLab