diff options
author | John Kohl <jtkohl@mit.edu> | 1987-08-04 13:30:47 +0000 |
---|---|---|
committer | John Kohl <jtkohl@mit.edu> | 1987-08-04 13:30:47 +0000 |
commit | 10208360b6d7f9dc8b70dbfc65df152a4029c5d2 (patch) | |
tree | 23013ad6edf312a199e1a7392f073ba8c91b2554 /server/subscr.c | |
parent | 7893c3a53ad3d855c3130e2cfaef3bc19449fdfb (diff) |
Fix problem with sending replies to "GIMME" requests with no
subscriptions
Diffstat (limited to 'server/subscr.c')
-rw-r--r-- | server/subscr.c | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/server/subscr.c b/server/subscr.c index 07967f6..71305bc 100644 --- a/server/subscr.c +++ b/server/subscr.c @@ -417,28 +417,42 @@ struct sockaddr_in *who; ZNotice_t reply; ZPacket_t reppacket; int packlen, i, found = 0; - char **answer; + char **answer = (char **) NULL; - if (!client || !client->zct_subs) { - clt_ack(notice, who, NOT_FOUND); - return; - } + if (client && client->zct_subs) { - /* check authenticity here. The user must be authentic to get - a list of subscriptions. If he is not subscribed to anything, - the above test hits, and he gets a response indicating no - subscriptions */ + /* check authenticity here. The user must be authentic to get + a list of subscriptions. If he is not subscribed to + anything, the above test fails, and he gets a response + indicating no subscriptions */ - if (!auth) { - clt_ack(notice, who, AUTH_FAILED); - return; - } + if (!auth) { + clt_ack(notice, who, AUTH_FAILED); + return; + } - for (subs = client->zct_subs->q_forw; - subs != client->zct_subs; - subs = subs->q_forw, found++); + for (subs = client->zct_subs->q_forw; + subs != client->zct_subs; + subs = subs->q_forw, found++); - /* found is now the number of subscriptions */ + /* found is now the number of subscriptions */ + + /* coalesce the subscription information into a list of + char *'s */ + if ((answer = (char **) xmalloc(found * NUM_FIELDS * sizeof(char *))) == (char **) 0) { + syslog(LOG_ERR, "subscr no mem(answer)"); + found = 0; + } else + for (i = 0, subs = client->zct_subs->q_forw; + i < found ; + i++, subs = subs->q_forw) { + answer[i*NUM_FIELDS] = subs->zst_class; + answer[i*NUM_FIELDS + 1] = subs->zst_classinst; + answer[i*NUM_FIELDS + 2] = subs->zst_recipient; + } + } + /* note that when there are no subscriptions, found == 0, so + we needn't worry about answer being NULL */ reply = *notice; reply.z_kind = SERVACK; @@ -447,19 +461,6 @@ struct sockaddr_in *who; packlen = sizeof(reppacket); - /* coalesce the subscription information into a list of char *'s */ - if ((answer = (char **) xmalloc(found * NUM_FIELDS * sizeof(char *))) == (char **) 0) { - syslog(LOG_ERR, "subscr no mem(answer)"); - found = 0; - } else - for (i = 0, subs = client->zct_subs->q_forw; - i < found ; - i++, subs = subs->q_forw) { - answer[i*NUM_FIELDS] = subs->zst_class; - answer[i*NUM_FIELDS + 1] = subs->zst_classinst; - answer[i*NUM_FIELDS + 2] = subs->zst_recipient; - } - /* if it's too long, chop off one at a time till it fits */ while ((retval = ZFormatRawNoticeList(&reply, answer, |