Config file include order bug?

Sven Hartge sven at svenhartge.de
Thu Jul 16 14:56:15 CEST 2020


Um 08:37 Uhr am 16.07.20 schrieb Alan DeKok:

> On Jul 16, 2020, at 8:33 AM, Sven Hartge <sven at svenhartge.de> wrote:
> > Out if interest: can you share your test-code? I'd like to experiment
> > with it.
> 
> The basic use-case was calling scandir() with NULL for the selector function, and alphasort() for the sorting function, as in your patch.
> 
> It's hard for me to see how anything can go wrong...

Yes, I can see that. Really interesting.

Here is the simple test tool I wrote. As you can see, it also contains
part of the freeradius code to remove unwanted filenames to test that *dp
is really the same is the one readdir() spits out.

----------------------------8<-------------------

#define _DEFAULT_SOURCE
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int
main(void)
{
    struct dirent **namelist;
    struct dirent *dp;
    int n,i;

    n = scandir(".", &namelist, NULL, alphasort);
    if (n == -1) {
        perror("scandir");
        exit(EXIT_FAILURE);
    }

    for (i=0; i<n; i++) {
				char const *p;
        dp = namelist[i];
        free(namelist[i]);

        if (dp->d_name[0] == '.') continue;

          for (p = dp->d_name; *p != '\0'; p++) {
            if (isalpha((int)*p) ||
                isdigit((int)*p) ||
                (*p == '-') ||
                (*p == '_') ||
                (*p == '.')) continue;
            break;
          }
          if (*p != '\0') continue;

        printf("%d: %lu: %s\n", i, dp->d_ino, dp->d_name);
    }

    free(namelist);

    exit(EXIT_SUCCESS);
}

----------------------------8<-------------------

Does this also show the same issues?

Grüße,
Sven.


More information about the Freeradius-Users mailing list