Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Yahoo!, Bing, Sogou

Members: 0
Guests: 6
Stats
Files
Topics
Posts
Members
Newest Member
477
3,706
19,240
608
LAntorcha
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,639
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 >>