Login
User Name:

Password:



Register

Forgot your password?
Overland with Bitmaps
Jul 4, 2025 11:57 pm
By Samson
void nanny_get_new_race -- comm.c
Mar 13, 2025 7:08 am
By Elwood
IPv6
Jan 25, 2025 10:45 pm
By Samson
mudstrlcpy and mudstrlcat
Jan 18, 2025 5:23 pm
By Samson
I3 and IMC
Jan 17, 2025 9:35 pm
By Samson
SWFotEFUSS 1.5.3
Author: Various
Submitted by: Samson
SWRFUSS 1.4.3
Author: Various
Submitted by: Samson
SmaugFUSS 1.9.8
Author: Various
Submitted by: Samson
AFKMud 2.5.2
Author: AFKMud Team
Submitted by: Samson
SmaugFUSS 1.9.7
Author: Various
Submitted by: Samson
Users Online
Anthropic, Majestic-12, DotBot

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
507
3,812
19,727
601
PedroJooLu

» SmaugMuds » 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 12:29 pm   Last edited Nov 12, 2006 12:31 pm by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,708
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 >>