Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, DotBot, Yandex

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
481
3,739
19,386
619
Alexander
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Bugfix Lists » AFKMud Bugfix List » AFKMud Bug Archive » [Bug] Pfile pruner has severa...
Forum Rules | Mark all | Recent Posts

[Bug] Pfile pruner has several problems
< Newer Topic :: Older Topic > AFKMud 1.77

Pages:<< prev 1 next >>
Post is unread #1 Nov 12, 2006, 10:29 am   Last edited Nov 12, 2006, 10:31 am by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

Bug: Pfile pruner has several problems
Danger: Medium - Possible infinite loop on file read, bad string display for status messages
Discovered in: AFKMud 1.77
Found by: Toadvile
Fixed by: Toadvile/Samson

---

pfiles.c, fread_pfile

Replace the function with this new one:
void fread_pfile( FILE * fp, time_t tdiff, char *fname, bool count )
{
   char *name = NULL;
   char *clan = NULL;
   char *deity = NULL;
   short level = 0;
   short file_ver = 0;
   EXT_BV pact;

   bool fMatch;

   xCLEAR_BITS( pact );
   for( ;; )
   {
      const char *word = ( feof( fp ) ? "End" : fread_word( fp ) );

      if( word[0] == '\0' )
      {
         bug( "%s: EOF encountered reading file!", __FUNCTION__ );
         word = "End";
      }

      if( !str_cmp( word, "End" ) )
         break;

      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case '*':
            fMatch = TRUE;
            fread_to_eol( fp );
            break;

         case 'A':
            KEY( "Act", pact, fread_bitvector( fp ) );
            if( !str_cmp( word, "ActFlags" ) )
            {
               char *actflags = NULL;
               char flag[MIL];
               int value;

               actflags = fread_flagstring( fp );
               while( actflags[0] != '\0' )
               {
                  actflags = one_argument( actflags, flag );
                  if( file_ver < 18 )
                     value = get_actflag( flag );
                  else
                     value = get_plrflag( flag );
                  if( value < 0 || value > MAX_BITS )
                     bug( "%s: Unknown flag: %s\n\r", fname, flag );
                  else
                     xSET_BIT( pact, value );
               }
               fMatch = TRUE;
               break;
            }
            break;

         case 'C':
            KEY( "Clan", clan, fread_string( fp ) );
            break;

         case 'D':
            KEY( "Deity", deity, fread_string( fp ) );
            break;

         case 'L':
            KEY( "Level", level, fread_number( fp ) );
            break;

         case 'N':
            KEY( "Name", name, fread_string( fp ) );
            break;

         case 'S':
            if( !str_cmp( word, "Status" ) )
            {
               level = fread_number( fp );
               fread_to_eol( fp );
               fMatch = TRUE;
               break;
            }
            break;

         case 'V':
            KEY( "Version", file_ver, fread_number( fp ) );
            break;
      }
      if( !fMatch )
         fread_to_eol( fp );
   }

   if( count == FALSE && !xIS_SET( pact, PLR_EXEMPT ) )
   {
      if( level < 10 && tdiff > sysdata.newbie_purge )
      {
         if( unlink( fname ) == -1 )
            perror( "Unlink" );
         else
         {
            days = sysdata.newbie_purge;
            log_printf( "Player %s was deleted. Exceeded time limit of %d days.", name, days );
            remove_from_auth( name );
            if( clan != NULL )
               remove_member( clan, name );
            deleted++;
            STRFREE( clan );
            STRFREE( deity );
            STRFREE( name );
            return;
         }
      }

      if( level < LEVEL_IMMORTAL && tdiff > sysdata.regular_purge )
      {
         if( level < LEVEL_IMMORTAL )
         {
            if( unlink( fname ) == -1 )
               perror( "Unlink" );
            else
            {
               days = sysdata.regular_purge;
               log_printf( "Player %s was deleted. Exceeded time limit of %d days.", name, days );
               remove_from_auth( name );
               if( clan != NULL )
                  remove_member( clan, name );
               deleted++;
               STRFREE( clan );
               STRFREE( deity );
               STRFREE( name );
               return;
            }
         }
      }
   }

   if( clan != NULL )
   {
      CLAN_DATA *guild = get_clan( clan );

      if( guild )
         guild->members++;
   }

   if( deity != NULL )
   {
      DEITY_DATA *god = get_deity( deity );

      if( god )
         god->worshippers++;
   }
   STRFREE( clan );
   STRFREE( deity );
   STRFREE( name );
   return;
}


The old function had a number of problems. The most important of which was it had no protection against getting caught in an infinite loop if the file ended prematurely. It also employed the use of a goto statement, which is just plain heretical. And because it used static variables to hold some of the temporary information read from the files, the status messages would come out with corrupt information in them.
       
Pages:<< prev 1 next >>