commit cf758c3329364c1516e2b78c573d6901843bc670 from: Omar Polo date: Tue Dec 14 22:12:20 2021 UTC fix Tattach handling The previous implementation assumed that you can't attach more than once. This is clearly wrong, Tattach and Twalk are the two ways to obtain new fids. This drops the error on subsequential attach and making the test "multiple attach" passes. commit - a47c234bedbcc16108a0e4f03b6f333ef72729c8 commit + cf758c3329364c1516e2b78c573d6901843bc670 blob - 942a9436ab608ca818a0e6788a6d48774c385bbe blob + 5acf852dec04af7440d6eb40c4a8f159f7f7a8b4 --- client.c +++ client.c @@ -76,7 +76,7 @@ static struct imsgev *iev_listener; static struct evbuffer *evb; static uint32_t peerid; -static int handshaked, attached; +static int handshaked; uint32_t msize; static ATTR_DEAD void client_shutdown(void); @@ -411,9 +411,6 @@ qid_decref(struct qid *qid) close(qid->fd); free(qid); - - if (STAILQ_EMPTY(&qids)) - attached = 0; } static struct fid * @@ -781,11 +778,6 @@ tattach(struct np_msg_header *hdr, const uint8_t *data uint32_t fid, afid; int fd; char aname[PATH_MAX]; - - if (attached) { - np_error(hdr->tag, "already attached"); - return; - } /* fid[4] afid[4] uname[s] aname[s] */ @@ -807,6 +799,11 @@ tattach(struct np_msg_header *hdr, const uint8_t *data goto err; case READSTRTRUNC: np_error(hdr->tag, "name too long"); + return; + } + + if (fid_by_id(fid) != NULL || afid != NOFID) { + np_error(hdr->tag, "invalid fid or afid"); return; } @@ -816,7 +813,7 @@ tattach(struct np_msg_header *hdr, const uint8_t *data if ((qid = qid_from_fd(fd, NULL, NULL)) == NULL) goto fail; - log_debug("attached %s", aname); + log_debug("attached %s to %d", aname, fid); if ((f = new_fid(qid, fid)) == NULL) { qid_decref(qid); @@ -824,7 +821,6 @@ tattach(struct np_msg_header *hdr, const uint8_t *data } np_attach(hdr->tag, qid); - attached = 1; return; fail: