Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the compiler from destroying the source code #98

Open
fredrikr opened this issue Jun 8, 2021 · 6 comments
Open

Stop the compiler from destroying the source code #98

fredrikr opened this issue Jun 8, 2021 · 6 comments

Comments

@fredrikr
Copy link

fredrikr commented Jun 8, 2021

If you specify the name of the source code file twice on the commandline, the source code is overwritten with the compiled file, like:

inform6 +library mygame.inf -v5 -e -s -z mygame.inf

This is pretty nasty.

@erkyrath
Copy link
Contributor

erkyrath commented Jun 8, 2021

That seems like a special case which command-line tools generally do not worry about.

cc -o test.c test.c

This destroys test.c.

It could only be fixed in a narrow sense, anyhow. We could try to compare the filenames, but that wouldn't catch inform test.inf ./test.inf or inform test.inf TEST.INF. Not to mention overwriting library files or other files.

@fredrikr
Copy link
Author

fredrikr commented Jun 8, 2021

Maybe refuse to write to files ending with .inf? That's the major risk here.

@heasm66
Copy link
Contributor

heasm66 commented Dec 13, 2024

A simple check that output file is not *.inf, *.c or *.h?

inform.c

@@ -1916,6 +1916,19 @@ static int sub_main(int argc, char **argv)

    read_command_line(argc, argv);

    int32 len = strlen(cli_file2);
    char s[4];
    int32 i;
    for (i = 0; i < 4; i++)
        s[i] = cli_file2[len - 4 + i];
    make_lower_case(s);
    if ((s[0] == '.' && s[1] == 'i' && s[2] == 'n' && s[3] == 'f') ||
        (s[2] == '.' && s[3] == 'c') ||
        (s[2] == '.' && s[3] == 'h')) {
        printf("\n[No compilation completed. Output file extension can't be '*.inf', '*.c' or '*.h'.]\n");
        return(0);
    }

    if (cli_files_specified > 0)
    {   return_code = compile(cli_files_specified, cli_file1, cli_file2);


@erkyrath
Copy link
Contributor

erkyrath commented Dec 19, 2024

I still think this is a bad idea. Even aside from the question of deciding which suffixes to watch for. (They're configured in header.h, not necessarily ".inf" even though we assume that these days. And nothing about the compiler requires you to use ".inf" and ".h" extensions on your files.)

There's a lot of mistakes you can make on the command line. Fixes like this will not prevent all of them and will prevent some things that are currently legal. It seems like a misconceived idea and I think it should be closed.

@heasm66
Copy link
Contributor

heasm66 commented Dec 19, 2024

I tend to agree.

@fredrikr
Copy link
Author

Sure, it will prevent some things that are currently legal. Like:

inform +lib mygame.inf mygame.inf

(This currently builds a z5 game called mygame.inf, overwriting the source code)

And while it wouldn't remove all risks, it would remove some risk.

But I don't expect to get get all my suggestions implemented. If you think it's a bad idea, that's fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants