From: Alfons Hoogervorst Date: Mon, 30 Apr 2001 21:27:59 +0000 (+0000) Subject: sync with 0.4.65cvs12 X-Git-Tag: disposition-notification~10 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=15c52ae7d7990d58b27540e2cbe44037c305d62e sync with 0.4.65cvs12 --- diff --git a/ChangeLog b/ChangeLog index 2f506988a..62fd78b6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2001-04-30 + + * src/recv.c: recv_bytes_write(): fixed another bug that caused + infinite loop and buffer overrun. + +2001-04-30 + + * src/socket.[ch]: renamed sock_read() and fd_read() to + sock_gets() and fd_gets() for preventing confusion. + Added sock_read() and fd_read() which is the wrapper of read(). + * src/recv.c: recv_bytes_write(): fixed a bug that caused infinite + loop. Use sock_read() instead of fd_read(). + * src/esmtp.c + src/imap.c + src/news.c + src/nntp.c + src/pop.c + src/recv.c + src/smtp.c: use sock_gets() instead of sock_read(). + * src/imap.c: imap_session_new(): fixed the error detection + of imap_open(). + 2001-04-28 * src/inc.c: made it displays current read bytes to the dialog. diff --git a/ChangeLog.claws b/ChangeLog.claws index 652196528..a695f8ece 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,11 @@ +2001-04-30 [alfons] + + 0.4.65claws7 + + * sync with 0.4.65cvs12 + + NOTE: nntp.c and news.c in claws and cvs branch differ significantly! + 2001-04-30 [sergey] * src/nntp.h (NNTPSockInfo): new field auth_failed. diff --git a/ChangeLog.jp b/ChangeLog.jp index b5b21bc28..1d441d8bf 100644 --- a/ChangeLog.jp +++ b/ChangeLog.jp @@ -1,3 +1,25 @@ +2001-04-30 + + * src/recv.c: recv_bytes_write(): ̵¸Â¥ë¡¼¥×¤È¥Ð¥Ã¥Õ¥¡¥ª¡¼¥Ð¡¼¥é¥ó + ¤òµ¯¤³¤¹¤â¤¦°ì¤Ä¤Î¥Ð¥°¤ò½¤Àµ¡£ + +2001-04-30 + + * src/socket.[ch]: º®Íð¤òÈò¤±¤ë¤¿¤á¡¢ sock_read() ¤È fd_read() ¤ò + sock_gets() ¤È fd_read() ¤Ë̾¾ÎÊѹ¹¡£ read() ¤Î¥é¥Ã¥Ñ¡¼¤Ç¤¢¤ë + sock_read() ¤È fd_read() ¤òÄɲᣠ+ * src/recv.c: recv_bytes_write(): ̵¸Â¥ë¡¼¥×¤òµ¯¤³¤¹¥Ð¥°¤ò½¤Àµ¡£ + fd_read() ¤ÎÂå¤ï¤ê¤Ë sock_read() ¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£ + * src/esmtp.c + src/imap.c + src/news.c + src/nntp.c + src/pop.c + src/recv.c + src/smtp.c: sock_read() ¤ÎÂå¤ï¤ê¤Ë sock_gets() ¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë + ¤·¤¿¡£ + * src/imap.c: imap_session_new(): imap_open() ¤Î¥¨¥é¡¼¸¡½Ð¤ò½¤Àµ¡£ + 2001-04-28 * src/inc.c: ¥À¥¤¥¢¥í¥°¤Ë¸½ºß¤ÎÆɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òɽ¼¨¤¹¤ë¤è¤¦¤Ë diff --git a/configure.in b/configure.in index fe3ce12ae..64818a450 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=4 MICRO_VERSION=65 INTERFACE_AGE=65 BINARY_AGE=65 -EXTRA_VERSION=claws6 +EXTRA_VERSION=claws7 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl diff --git a/src/imap.c b/src/imap.c index a6d6ee306..0d6c7d739 100644 --- a/src/imap.c +++ b/src/imap.c @@ -164,7 +164,7 @@ Session *imap_session_new(const gchar *server, gushort port, log_message(_("creating IMAP4 connection to %s:%d ...\n"), server, port); - if ((imap_sock = imap_open(server, port, buf)) < 0) + if ((imap_sock = imap_open(server, port, buf)) == NULL) return NULL; if (imap_auth(imap_sock, user, pass) != IMAP_SUCCESS) { imap_logout(imap_sock); @@ -524,7 +524,7 @@ static GSList *imap_get_uncached_messages(IMAPSession *session, } for (;;) { - if (sock_read(SESSION(session)->sock, buf, sizeof(buf)) < 0) { + if (sock_gets(SESSION(session)->sock, buf, sizeof(buf)) < 0) { log_warning(_("error occurred while getting envelope.\n")); return newlist; } @@ -751,7 +751,7 @@ static gint imap_get_message(SockInfo *sock, gint num, const gchar *filename) imap_gen_send(sock, "FETCH %d BODY[]", num); - if (sock_read(sock, buf, sizeof(buf)) < 0) + if (sock_gets(sock, buf, sizeof(buf)) < 0) return IMAP_ERROR; strretchomp(buf); if (buf[0] != '*' || buf[1] != ' ') @@ -820,7 +820,7 @@ static gchar *imap_parse_atom(SockInfo *sock, gchar *src, gchar *dest, g_return_val_if_fail(orig_buf != NULL, cur_pos); - if (sock_read(sock, orig_buf, IMAPBUFSIZE) < 0) + if (sock_gets(sock, orig_buf, IMAPBUFSIZE) < 0) return cur_pos; strretchomp(orig_buf); log_print("IMAP4< %s\n", orig_buf); @@ -1221,7 +1221,7 @@ static void imap_gen_send(SockInfo *sock, const gchar *format, ...) static gint imap_gen_recv(SockInfo *sock, gchar *buf, gint size) { - if (sock_read(sock, buf, size) == -1) + if (sock_gets(sock, buf, size) == -1) return IMAP_SOCKET; strretchomp(buf); diff --git a/src/pop.c b/src/pop.c index 905c15f80..0f76e109d 100644 --- a/src/pop.c +++ b/src/pop.c @@ -242,7 +242,7 @@ gint pop3_getrange_uidl_recv(SockInfo *sock, gpointer data) nb = sock_is_nonblocking_mode(sock); if (nb && (sock_set_nonblocking_mode(sock, FALSE) < 0)) return -1; - while (sock_read(sock, buf, sizeof(buf)) >= 0) { + while (sock_gets(sock, buf, sizeof(buf)) >= 0) { gint num; if (buf[0] == '.') break; @@ -293,7 +293,7 @@ gint pop3_getsize_list_recv(SockInfo *sock, gpointer data) nb = sock_is_nonblocking_mode(sock); if (nb && (sock_set_nonblocking_mode(sock, FALSE) < 0)) return -1; - while (sock_read(sock, buf, sizeof(buf)) >= 0) { + while (sock_gets(sock, buf, sizeof(buf)) >= 0) { gint num, size; if (buf[0] == '.') break; @@ -479,7 +479,7 @@ static gint pop3_gen_recv(SockInfo *sock, gchar *buf, gint size) if (nb && (sock_set_nonblocking_mode(sock, FALSE) < 0)) return PS_SOCKET; - if (sock_read(sock, buf, size) < 0) { + if (sock_gets(sock, buf, size) < 0) { return PS_SOCKET; } else { strretchomp(buf); diff --git a/src/recv.c b/src/recv.c index 25c814d77..dabe7d93e 100644 --- a/src/recv.c +++ b/src/recv.c @@ -106,7 +106,7 @@ gint recv_write(SockInfo *sock, FILE *fp) if (nb) sock_set_nonblocking_mode(sock, FALSE); for (;;) { - if (sock_read(sock, buf, sizeof(buf)) < 0) { + if (sock_gets(sock, buf, sizeof(buf)) < 0) { g_warning(_("error occurred while retrieving data.\n")); if (nb) sock_set_nonblocking_mode(sock, TRUE); return -1; @@ -157,10 +157,9 @@ gint recv_bytes_write(SockInfo *sock, glong size, FILE *fp) Xalloca(buf, size, return -1); do { - size_t read_count; + gint read_count; - /* FIXME: put this into socket.c :WK: */ - read_count = fd_read(sock->sock, buf + count, size - count); + read_count = sock_read(sock, buf + count, size - count); if (read_count < 0) { if (nb) sock_set_nonblocking_mode(sock, TRUE); return -1; @@ -168,19 +167,27 @@ gint recv_bytes_write(SockInfo *sock, glong size, FILE *fp) count += read_count; } while (count < size); + /* +------------------+----------------+--------------------------+ * + * ^buf ^prev ^cur buf+size-1^ */ + prev = buf; - while ((cur = memchr(prev, '\r', size)) != NULL) { - if (cur - buf + 1 < size && *(cur + 1) == '\n') { - if (fwrite(prev, sizeof(gchar), cur - prev, fp) == EOF || - fwrite("\n", sizeof(gchar), 1, fp) == EOF) { - perror("fwrite"); - g_warning(_("Can't write to file.\n")); - if (nb) sock_set_nonblocking_mode(sock, TRUE); - return -1; - } - prev = cur + 2; - if (prev - buf >= size) break; + while ((cur = memchr(prev, '\r', size - (prev - buf))) != NULL) { + if (cur == buf + size - 1) break; + + if (fwrite(prev, sizeof(gchar), cur - prev, fp) == EOF || + fwrite("\n", sizeof(gchar), 1, fp) == EOF) { + perror("fwrite"); + g_warning(_("Can't write to file.\n")); + if (nb) sock_set_nonblocking_mode(sock, TRUE); + return -1; } + + if (*(cur + 1) == '\n') + prev = cur + 2; + else + prev = cur + 1; + + if (prev - buf >= size) break; } if (prev - buf < size && fwrite(buf, sizeof(gchar), diff --git a/src/smtp.c b/src/smtp.c index f5107d342..210810149 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -135,7 +135,7 @@ gint smtp_eom(SockInfo *sock) gint smtp_ok(SockInfo *sock) { - while ((sock_read(sock, smtp_response, sizeof(smtp_response) - 1)) + while ((sock_gets(sock, smtp_response, sizeof(smtp_response) - 1)) != 1) { if (strlen(smtp_response) < 4) return SM_ERROR; diff --git a/src/socket.c b/src/socket.c index 9a1d8eb0f..dc08c1bf2 100644 --- a/src/socket.c +++ b/src/socket.c @@ -163,7 +163,7 @@ static gboolean is_nonblocking_mode(gint fd) gboolean sock_is_nonblocking_mode(SockInfo *sock) { - g_assert(sock); + g_return_val_if_fail(sock != NULL, FALSE); return is_nonblocking_mode(sock->sock); } @@ -391,6 +391,18 @@ gint sock_printf(SockInfo *sock, const gchar *format, ...) return sock_write(sock, buf, strlen(buf)); } +gint sock_read(SockInfo *sock, gchar *buf, gint len) +{ + g_return_val_if_fail(sock != NULL, -1); + + return fd_read(sock->sock, buf, len); +} + +gint fd_read(gint fd, gchar *buf, gint len) +{ + return read(fd, buf, len); +} + gint sock_write(SockInfo *sock, const gchar *buf, gint len) { g_return_val_if_fail(sock != NULL, -1); @@ -414,14 +426,7 @@ gint fd_write(gint fd, const gchar *buf, gint len) return wrlen; } -gint sock_read(SockInfo *sock, gchar *buf, gint len) -{ - g_return_val_if_fail(sock != NULL, -1); - - return fd_read(sock->sock, buf, len); -} - -gint fd_read(gint fd, gchar *buf, gint len) +gint fd_gets(gint fd, gchar *buf, gint len) { gchar *newline, *bp = buf; gint n; @@ -443,6 +448,14 @@ gint fd_read(gint fd, gchar *buf, gint len) return bp - buf; } +gint sock_gets(SockInfo *sock, gchar *buf, gint len) +{ + g_return_val_if_fail(sock != NULL, -1); + + return fd_gets(sock->sock, buf, len); +} + + gint sock_puts(SockInfo *sock, const gchar *buf) { gint ret; diff --git a/src/socket.h b/src/socket.h index 3cb423f4c..c532a81f0 100644 --- a/src/socket.h +++ b/src/socket.h @@ -74,8 +74,9 @@ SockInfo *sock_connect_with_thread (const gchar *hostname, gushort port); gint sock_printf (SockInfo *sock, const gchar *format, ...) G_GNUC_PRINTF(2, 3); +gint sock_read (SockInfo *sock, gchar *buf, gint len); gint sock_write (SockInfo *sock, const gchar *buf, gint len); -gint sock_read (SockInfo *sock, gchar *buf, gint len); +gint sock_gets (SockInfo *sock, gchar *buf, gint len); gint sock_puts (SockInfo *sock, const gchar *buf); gint sock_close (SockInfo *sock);