9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] manual suggestions and upas/fs bug
@ 2002-09-17  4:58 Russ Cox
  0 siblings, 0 replies; 12+ messages in thread
From: Russ Cox @ 2002-09-17  4:58 UTC (permalink / raw)
  To: 9fans

Thanks for your suggestions.  I've updated the
man pages and made the fixes to upas/fs.

I take back what I said yesterday or the day
before about IMAP being much slower than POP.
It appears that I fixed that (the overhead I was
remembering was due to constantly redialing rather
than staying dialed in, but now the code
stays dialed in).

Russ


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-18  2:06 ` Lyndon Nerenberg
@ 2002-09-18 17:03   ` rob pike, esq.
  0 siblings, 0 replies; 12+ messages in thread
From: rob pike, esq. @ 2002-09-18 17:03 UTC (permalink / raw)
  To: 9fans

> (For the record: I'm a server author ;-)
>
> If I ever get my P9 network re-built I plan to fix up the IMAP
> code.

Great.  For the record, the upas/fs implementation of IMAP is
something of a hack; of more interest to me is the correctness
of the stand-alone IMAP server, imap4d.  (I'm using it as I write
this.)  It's been tested - and fixed - against a number of clients
but it was written by someone learning IMAP as he went, so I'm sure
it's still got some issues.

-rob



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-17  9:17   ` Lucio De Re
@ 2002-09-18  8:37     ` Douglas A. Gwyn
  0 siblings, 0 replies; 12+ messages in thread
From: Douglas A. Gwyn @ 2002-09-18  8:37 UTC (permalink / raw)
  To: 9fans

Lucio De Re wrote:
>         char *p0 = realloc(p, n);
>         if (p0 == 0)
>                 panic ("realloc failed");
>         p = p0;
> would be a lot saner.  I forget the semantics, but realloc(p, n) need
> not return p even if the reallocation succeeds.  What I don't know is
> what happens to the space pointed to by p, I assume it's released.

Actually you don't have to be very careful if you're going to abort
anyway.  (Although the returned pointer needs to be checked, even
for a shrink request.)  But if you want to recover more intelligently,
you don't want to lose the old pointer if the realloc fails; either
the old data needs to be retained (so you need to use the old pointer)
or else you want to free the old storage (otherwise you have a memory
leak, which will exacerbate the tight-storage situation).


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-17 23:05 Russ Cox
@ 2002-09-18  2:06 ` Lyndon Nerenberg
  2002-09-18 17:03   ` rob pike, esq.
  0 siblings, 1 reply; 12+ messages in thread
From: Lyndon Nerenberg @ 2002-09-18  2:06 UTC (permalink / raw)
  To: 9fans

    -> 9X4 UID FETCH 1:* UID
    >> 9X4 BAD Invalid sequence in FETCH

    Russ> I don't see why it's invalid and not just empty,

Because the protocol provides other means for discovering how many
messages are in a folder. The client is responsible for determining the
state of the mailbox. Having done so, it should never be in a position
where it issues a FETCH when there are no messages present. The IMAP4
protocol specification is very picky about syntax. It (and most server
implementations) don't allow for *any* reading-in of semantic (or
syntactic) behaviour. (Another example of this is the illegality of
inserting extra whitespace between protocol elements.)

Some people (usually client authors) complain that this is just
a pain in the rear. Others (usually server authors) think it's
a wonderful way to avoid ambiguous behaviour in the protocol.
(For the record: I'm a server author ;-)

If I ever get my P9 network re-built I plan to fix up the IMAP
code.

--lyndon


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
@ 2002-09-17 23:05 Russ Cox
  2002-09-18  2:06 ` Lyndon Nerenberg
  0 siblings, 1 reply; 12+ messages in thread
From: Russ Cox @ 2002-09-17 23:05 UTC (permalink / raw)
  To: 9fans

> We have both client and server bugs here.

Thanks for your pointers.  The IMAP client code has been
cobbled together by a few people (myself included) who knew
nothing about IMAP before working on it, so it's not surprising
that these inefficiencies exist.

> And *again* the server said there were no messages, thus
>
>    -> 9X4 UID FETCH 1:* UID
>
> is completely bogus. That message range is invalid, and the client
> should know that. However, the server should be responding with
> something like
>
>    9X4 BAD Invalid sequence in FETCH

I don't see why it's invalid and not just empty,
but I agree that it is inefficient for the client to
be sending it.

Russ



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-17  4:34 David Swasey
@ 2002-09-17 20:18 ` Lyndon Nerenberg
  0 siblings, 0 replies; 12+ messages in thread
From: Lyndon Nerenberg @ 2002-09-17 20:18 UTC (permalink / raw)
  To: 9fans

We have both client and server bugs here.

   -> 9X2 SELECT Inbox
   <- * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
   <- * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)]
   <- * 0 EXISTS
   <- * 0 RECENT
   <- * OK [UIDVALIDITY 1031763467]
   <- 9X2 OK [READ-WRITE] Completed

Notice how the server states there are no messages in the mailbox.

   -> 9X3 STATUS Inbox (MESSAGES UIDVALIDITY)

This command should not be issued, for several reasons.

    1) The SELECT response already told the client the number of messages.

    2) The SELECT response already told the client the uidvalidity
       of the mailbox.

    3) Queries to the currently selected folder should be done using
       FETCH and LIST. STATUS is for querying folders other than the
       selected one, and is not guaranteed to be fast.  (In many
       servers, selecting a folder causes the meta data about the folder
       to assembled and cached. SELECT will not use that data cache
       since its assuming you want to know something about a folder
       other than the selected one.)

   <- * STATUS Inbox (MESSAGES 0 UIDVALIDITY 1031763467)
   <- 9X3 OK Completed

And *again* the server said there were no messages, thus

   -> 9X4 UID FETCH 1:* UID

is completely bogus. That message range is invalid, and the client
should know that. However, the server should be responding with
something like

   9X4 BAD Invalid sequence in FETCH

instead of dumping core (and that's the server bug I mentioned).

--lyndon


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
@ 2002-09-17 13:28 Russ Cox
  0 siblings, 0 replies; 12+ messages in thread
From: Russ Cox @ 2002-09-17 13:28 UTC (permalink / raw)
  To: 9fans

> p = realloc(p,n) is almost always a mistake.  If the allocation
> fails, the previous pointer value in p gets replaced by a null
> pointer value, so you lose the handle to the data that did not
> get extended (or, rarely, shrunk).

maybe this is what lucio was getting at, but when the next line is

	if(p == 0)
		sysfatal("out of memory");

then it doesn't really matter that we've lost the old p.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-17  8:47 ` Douglas A. Gwyn
@ 2002-09-17  9:17   ` Lucio De Re
  2002-09-18  8:37     ` Douglas A. Gwyn
  0 siblings, 1 reply; 12+ messages in thread
From: Lucio De Re @ 2002-09-17  9:17 UTC (permalink / raw)
  To: 9fans

On Tue, Sep 17, 2002 at 08:47:45AM +0000, Douglas A. Gwyn wrote:
> > >       if(n==0){
> > >               free(p);
> > >               p = malloc(n);
> > >       } else
> > >               p = realloc(p, n);
>
> p = realloc(p,n) is almost always a mistake.  If the allocation
> fails, the previous pointer value in p gets replaced by a null
> pointer value, so you lose the handle to the data that did not
> get extended (or, rarely, shrunk).

In other words,

	if (n==0)
		panic ("zero size");
	p = realloc(p, n);

is closer to the intent here.  Better still

	char *p0 = realloc(p, n);

	if (p0 == 0)
		panic ("realloc failed");
	p = p0;

would be a lot saner.  I forget the semantics, but realloc(p, n) need
not return p even if the reallocation succeeds.  What I don't know is
what happens to the space pointed to by p, I assume it's released.

++L


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-16 19:29 David Swasey
  2002-09-17  1:58 ` Lyndon Nerenberg
@ 2002-09-17  8:47 ` Douglas A. Gwyn
  2002-09-17  9:17   ` Lucio De Re
  1 sibling, 1 reply; 12+ messages in thread
From: Douglas A. Gwyn @ 2002-09-17  8:47 UTC (permalink / raw)
  To: 9fans

David Swasey wrote:
> The malloc(2) page says:
>         The call realloc(0, size) means the same as `malloc(size)'.
>         Further, the call realloc(ptr, 0) means the same as
>         `free(ptr)'.
> I suggest you clarify the meaning of realloc(0,0).

If the intention is to be standard-conforming, then realloc(0,x)
is the same as malloc(x) for all x.  malloc(0) is required to
return either a null pointer or a valid heap pointer (which a
strictly conforming program is not allowed to dereference).

realloc(p,0) cannot be identical to free(p) since the former
returns a value and the latter does not.  Presumably it acts
as free(p) then does not succeed in allocating a 0-sized new
object, thus returns a null pointer.

free(0) is required to be a no-op.

> diff /n/dump/2002/0916/sys/src/cmd/upas/fs/mbox.c mbox.c
> 1358c1358,1362
> <       p = realloc(p, n);
> ---
> >       if(n==0){
> >               free(p);
> >               p = malloc(n);
> >       } else
> >               p = realloc(p, n);

p = realloc(p,n) is almost always a mistake.  If the allocation
fails, the previous pointer value in p gets replaced by a null
pointer value, so you lose the handle to the data that did not
get extended (or, rarely, shrunk).


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
@ 2002-09-17  4:34 David Swasey
  2002-09-17 20:18 ` Lyndon Nerenberg
  0 siblings, 1 reply; 12+ messages in thread
From: David Swasey @ 2002-09-17  4:34 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 788 bytes --]

I did not spend much time on this and am not an authority on IMAP or
upas/fs.  I could be wrong.

>Can you send me an
>IMAP protocol trace? (Along with the banner from the server.)

The trace is attached.  "8.out" is upas/fs with modified erealloc,
with the original imap4read, and with line 794 of imap.c changed to
read

	imap->debug = 1;

I modified the trace to hide my password.  Let me know if you had
something else in mind.

>What does "not like" mean in this context?

It appears the server closed the connection.  Since there is no "<-"
in the trace following the UID FETCH command, I think the first
Brdline call in imap4resp returned zero.

If it helps, I can temporarily deliver my mail elsewhere and give you
my password to this IMAP server.

-dave

[-- Attachment #2: Type: text/plain, Size: 614 bytes --]

term% ./8.out -f /imap/postoffice.srv.cs.cmu.edu
<- * OK postoffice.srv.cs.cmu.edu Cyrus IMAP4 v1.5.2 server ready
-> 9X1 LOGIN swasey ***************
<- 9X1 OK User logged in
-> 9X2 SELECT Inbox
<- * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
<- * OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)]
<- * 0 EXISTS
<- * 0 RECENT
<- * OK [UIDVALIDITY 1031763467]
<- 9X2 OK [READ-WRITE] Completed
-> 9X3 STATUS Inbox (MESSAGES UIDVALIDITY)
<- * STATUS Inbox (MESSAGES 0 UIDVALIDITY 1031763467)
<- 9X3 OK Completed
-> 9X4 UID FETCH 1:* UID
./8.out: opening mailbox: i/o error
term%

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [9fans] manual suggestions and upas/fs bug
  2002-09-16 19:29 David Swasey
@ 2002-09-17  1:58 ` Lyndon Nerenberg
  2002-09-17  8:47 ` Douglas A. Gwyn
  1 sibling, 0 replies; 12+ messages in thread
From: Lyndon Nerenberg @ 2002-09-17  1:58 UTC (permalink / raw)
  To: 9fans

>>>>> "David" == David Swasey <swasey@cs.cmu.edu> writes:

    David> Second, the
    David> IMAP4 server I talk to (cyrus) does not like the command "UID
    David> FETCH 1:* UID" when there are no messages.

What does "not like" mean in this context? Can you send me an
IMAP protocol trace? (Along with the banner from the server.)

--lyndon


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [9fans] manual suggestions and upas/fs bug
@ 2002-09-16 19:29 David Swasey
  2002-09-17  1:58 ` Lyndon Nerenberg
  2002-09-17  8:47 ` Douglas A. Gwyn
  0 siblings, 2 replies; 12+ messages in thread
From: David Swasey @ 2002-09-16 19:29 UTC (permalink / raw)
  To: 9fans

Hi,

The malloc(2) page says:

	The call realloc(0, size) means the same as `malloc(size)'.
	Further, the call realloc(ptr, 0) means the same as
	`free(ptr)'.

I suggest you clarify the meaning of realloc(0,0).

The manual pages filter(1), mail(1), marshal(1), mlmgr(1), nedmail(1),
upasfs(4), pop3(8), send(8), and smtp(8) refer to aliasmail(1) which
does not exist.  The file /sys/man/8/INDEX.html refers to aliasmail(8)
which exists.  I suggest you decide if its aliasmail(8) or
aliasmail(1) and make the appropriate changes.

Upas/fs dies when working with an empty IMAP4 mail box.  There are two
problems, both in /sys/src/cmd/upas/fs/imap4.c:/^imap4read.  First,
when imap->nmsg is 0, the erealloc() call will fail.  Second, the
IMAP4 server I talk to (cyrus) does not like the command "UID FETCH
1:* UID" when there are no messages.  My fix was to change the
semantics of erealloc(_,0) and to avoid the offending IMAP command.
Diffs follow.

-dave

diff /n/dump/2002/0916/sys/src/cmd/upas/fs/imap4.c imap4.c
557,559c557,561
< 	imap4cmd(imap, "UID FETCH 1:* UID");
< 	if(!isokay(s = imap4resp(imap)))
< 		return s;
---
> 	if(imap->nmsg > 0){
> 		imap4cmd(imap, "UID FETCH 1:* UID");
> 		if(!isokay(s = imap4resp(imap)))
> 			return s;
> 	}
diff /n/dump/2002/0916/sys/src/cmd/upas/fs/mbox.c mbox.c
1358c1358,1362
< 	p = realloc(p, n);
---
> 	if(n==0){
> 		free(p);
> 		p = malloc(n);
> 	} else
> 		p = realloc(p, n);



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-09-18 17:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-17  4:58 [9fans] manual suggestions and upas/fs bug Russ Cox
  -- strict thread matches above, loose matches on Subject: below --
2002-09-17 23:05 Russ Cox
2002-09-18  2:06 ` Lyndon Nerenberg
2002-09-18 17:03   ` rob pike, esq.
2002-09-17 13:28 Russ Cox
2002-09-17  4:34 David Swasey
2002-09-17 20:18 ` Lyndon Nerenberg
2002-09-16 19:29 David Swasey
2002-09-17  1:58 ` Lyndon Nerenberg
2002-09-17  8:47 ` Douglas A. Gwyn
2002-09-17  9:17   ` Lucio De Re
2002-09-18  8:37     ` Douglas A. Gwyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).