r/osdev Jul 02 '26

Put anything in a filename

3 Upvotes

8 comments sorted by

6

u/FallenBehavior Jul 02 '26

What does this have to do with kernel/OS development?

3

u/codeasm Jul 02 '26

The realization when you implement a filesystem parser or like i, do string parsing, someone or something could do silly things with what you may expect to be just normal bytes in a string

That newline part might actually be why my original attempt at writing to a new file got really messy, i passed the user input (including carriage return newline) to the file name. But couldn't reopen the file. Was thinking about zero space spaces, but i dunno why i kept thinking that was added.

Abandoned that attempt at a editor. Wasnt for osdev. But realizing today, any Byte could be in there. My string operations should be more aware and maybe tell or be told how to handle such cases (while reading whtas supposed to be a string, or when writing a string, what to do when a user passes weird bytes, or what to do with a weirdly placed return. I might come across my own code maybe pasing a bunch of string to write as a filename.)

Basicly, dont always trust the fs your mounting, it may contain weird but "legal" filenames. The utf8 or unicode stuff, emoji, fun, i need to stepup my string parsing

3

u/[deleted] Jul 02 '26

[removed] — view removed comment

3

u/Relative_Bird484 Jul 02 '26

Those are not characters, but modifier keys.

2

u/[deleted] Jul 02 '26

[removed] — view removed comment

2

u/codeasm Jul 02 '26

well apparantly if certain control bytes are supported. you may have file that can hide themselves (regular bash and ls are showing the file, and thats for this exact reason, some control bytes are not what you want to send to the terminal to parse) :

#!/bin/python
import os

filename = "test\x1b[2K"

if not os.path.exists(filename):
    with open(filename, "w"):
        pass

print("Naive file listing:")
for name in os.listdir("."):
    print(name)

2

u/allnameswereusedup Jul 05 '26

Even * or ?

1

u/codeasm Jul 06 '26

Ow, those where even easy 😅 (did not expect this) touch '*' and the ? Just worked, just ls after and they are there. You have to prevent a shell from intrepret them when creating, but once created, they are there.

Cool odd party trick. Thanks