Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jul 2004 21:43:55 +0000
From:      Michael Joyner <mjoyner@vbservices.net>
To:        Steven Narmontas <snarmont@wnec.edu>
Cc:        freebsd-standards@freebsd.org
Subject:   Re: [Manhat]"Bug" detected... in fseek
Message-ID:  <40FEE39B.6070807@vbservices.net>
In-Reply-To: <003b01c468cc$914ac4f0$0810050a@narmontas>
References:  <003b01c468cc$914ac4f0$0810050a@narmontas>

next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The fseek command is *always* succeeding, on the seeks to BEFORE THE
BEGINNING OF THE FILE!

(if I remember my random access correctly, this is expected behavior, at
least in the positive direction, not sure if it supposed to work that
way in the negative direction though... maybe be a "standards"
compliancy bug of some sort)

as a result the following fread command is trying to read non-existant
data, and errno is set to 'file to big', (gotta love those error
messages... I am thinking it is taking the negative value for the raw
offset and treating it as an unsigned long internally, yielding a file
size and location that is bigger than 1 Terabyte) the modified version
below seems to work fine on FreeBSD w/o giving a segfault or anything
and should be functionally equivelant to the original, except for the
fread error check. :)

void
record_recent_logins (CONFIG_STRUCT *conf, USER_LOG_NODE *head)
{
~  USER_LOG_NODE *person_ptr;
~  char logpath[MAX_PATH + 1];
~  FILE *fp;
~  int i;

~  for (person_ptr = head; person_ptr; person_ptr = person_ptr->next)
~    {

~      for (i = 0; i < MAX_LOGINS; i++)
~        person_ptr->login_time[i] = (time_t) 0;

~      snprintf (logpath, MAX_PATH + 1, "%speople/%s/%s",
~                conf->course_path, person_ptr->user.username,
ACCESS_LOG_FNAME);
~      fp = fopen (logpath, "r");

~      if (fp)
~        {
~          for (i = 0; i < MAX_LOGINS; i++)
~            {
~                if (!fseek(fp, -((i + 1) * sizeof (time_t)), SEEK_END))
~                        fread (&(person_ptr->login_time[i]), sizeof
(time_t), 1, fp);
~            }
~          fclose (fp);
~        }
~    }
}



Steven Narmontas wrote:
| Michael,
|
| I'm very busy delivering Manhattan workshops all this week.
|
| I'll try to look into this issue early next week...
|
| Thanks,
| Steve Narmontas
|

| Error reading file
|
| Platform: FreeBSD 4-STABLE
| Manhattan: Version 2.4
|
| ideas?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFA/uObOElk0ppmOXwRAspqAJ91zJFrCsv6pdP9lTfldNQJsIK0dwCfVyon
3/ppajB8khPNE4tSmp0CO8c=
=fYa1
-----END PGP SIGNATURE-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40FEE39B.6070807>