]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix creation of the report's file name from the mangling of the user name
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 27 Dec 2010 12:30:34 +0000 (12:30 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 27 Dec 2010 12:30:34 +0000 (12:30 +0000)
The directory and file name to store a user's report is produced by
replacing any character but the letters, digits and a few safe
characters from the user name. But that name mangling was not dealing
properly with consecutive invalid characters. The result was, at best,
a truncated file name (without any real consequence) or, at worst, an
invalid character left in the file name.

userinfo.c

index 6d82aa1df4d4b2c99598da8005a38017cd728032..089a64110c22c5dbac4117e38079bf038e00d05c 100644 (file)
@@ -61,7 +61,7 @@ struct userinfostruct *userinfo_create(const char *userid)
 {
        struct usergroupstruct *group, *last;
        struct userinfostruct *user;
-       int i, lastuser;
+       int i, j, lastuser;
        int skip;
        int flen;
        int count, clen;
@@ -91,18 +91,19 @@ struct userinfostruct *userinfo_create(const char *userid)
        user->id[MAX_USER_LEN-1]='\0';
 
        skip=0;
-       for(i=0 ; userid[i] && i<MAX_USER_FNAME_LEN-1 ; i++) {
-               if(isalnum(userid[i]) || userid[i]=='-' || userid[i]=='_') {
-                       user->filename[i]=userid[i];
+       j=0;
+       for (i=0 ; userid[i] && j<MAX_USER_FNAME_LEN-1 ; i++) {
+               if (isalnum(userid[i]) || userid[i]=='-' || userid[i]=='_') {
+                       user->filename[j++]=userid[i];
                        skip=0;
                } else {
                        if (!skip) {
-                               user->filename[i]='_';
+                               user->filename[j++]='_';
                                skip=1;
                        }
                }
        }
-       user->filename[i]='\0';
+       user->filename[j]='\0';
        flen=i;
 
        count=0;