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

Fix issue with extension check #1

Open
wants to merge 1 commit into
base: syscalls
Choose a base branch
from

Conversation

klezVirus
Copy link

Hi man, the syscall version was not working because the file check against the binary was not working when compiled with MSVC. Indeed, when MSVC is used, the unistd function strcasecmp is replaced by stricmp. However, completely unexpectedely, while strcasecmp return 0 when the two strings are equal, the custom implementation stricmp return 0 when they are different. Indeed, following through the definition in donut.h:

#if defined(_MSC_VER)
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#define strcasecmp stricmp

And if we go and ivestigate in in clib.c, we can see that the stricmp implementation is:

int stricmp(const char *str1, const char *str2) {
    while (*str1 && *str2) {
      if ((*str1 | 0x20) != (*str2 | 0x20)) {
        return 0;
      }
      str1++; str2++;
    }
    return *str2 == 0;
}

Which evidentely return 0 if the two strings are different.

Hi man, the syscall version was not working because the file check against the binary was not working when compiled with MSVC.  Indeed, when MSVC is used, the unistd function strcasecmp is replaced by stricmp. However, completely unexpectedely, while `strcasecmp` return 0 when the two strings are equal, the custom implementation `stricmp` return 0 when they are different. Indeed, following through the definition in `donut.h`:

```
#if defined(_MSC_VER)
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "user32.lib")
#define strcasecmp stricmp
```

And if we go and ivestigate in in `clib.c`, we can see that the `stricmp` implementation is:

```
int stricmp(const char *str1, const char *str2) {
    while (*str1 && *str2) {
      if ((*str1 | 0x20) != (*str2 | 0x20)) {
        return 0;
      }
      str1++; str2++;
    }
    return *str2 == 0;
}
```
Which evidentely return 0 if the two strings are different.
@klezVirus
Copy link
Author

This is just a workaround for MSVC, actually. I think it would be better to change the stricmp implementation and re-change all of its occurrencies in the code when required.

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

Successfully merging this pull request may close these issues.

1 participant