Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wmbiff - handle incorrect replies from office365.com IMAP server #50

Open
tnais opened this issue Mar 27, 2023 · 0 comments
Open

wmbiff - handle incorrect replies from office365.com IMAP server #50

tnais opened this issue Mar 27, 2023 · 0 comments

Comments

@tnais
Copy link

tnais commented Mar 27, 2023

This nice IMAP server authors could have violated (did not check correctly) the RFC that should state that multiple blanks in a reply are not allowed.

No matter if putting multiple blanks in an imap reply is or is not legal, I prefer to patch my code to have wmbiff working. My solution was to replace strncpy with a replacement that copies a single blank each time multiple blanks are found.

Having issues committing the single changed file (dockapps/wmbiff/wmbiff/tlsComm.c I add my patch here.

---------------------------------------8<----------------------------------------------------------------------
From 1697c7f78874e66ac25f4249805f111fecc9ba18 Mon Sep 17 00:00:00 2001
Message-Id: 1697c7f78874e66ac25f4249805f111fecc9ba18.1679925131.git.saint@eng.it
In-Reply-To: f2bf4066c333a526d2f87733edb342acde7e466d.1679925131.git.saint@eng.it
References: f2bf4066c333a526d2f87733edb342acde7e466d.1679925131.git.saint@eng.it
From: Gian Uberto Lauri saint@eng.it
Date: Mon, 27 Mar 2023 15:40:56 +0200
Subject: [PATCH 2/2] #feature/handle_multiple_blanks - Handles wrong
(multiple blanks) answer from Office365 IMAP server

Changes to be committed:
modified: wmbiff/wmbiff/tlsComm.c

wmbiff/wmbiff/tlsComm.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/wmbiff/wmbiff/tlsComm.c b/wmbiff/wmbiff/tlsComm.c
index 03b8009..fb4731a 100644
--- a/wmbiff/wmbiff/tlsComm.c
+++ b/wmbiff/wmbiff/tlsComm.c
@@ -159,6 +159,35 @@ static int wait_for_it(int sd, int timeoutseconds)
return (FD_ISSET(sd, &readfds));
}

+/* exported for testing /
+/
This version converts sequence of multiple blanks into a single

    • blank. This overcomes, say, the bug in the imap server of a random
    • company who thinks it can disregard standards because it is big and
    • hard. (pun intended) */
      +extern char *
      +strncpy_trim_blanks(char *dest, const char *src, size_t n)
      +{
  • size_t i;
  •   int last_read_was_not_a_blank = 1;
    
  •   char *m_src = src, *m_dest = dest;
    
  •   char ch;
    
  •   for (i = 0; i < n && src[i] != '\0'; i++) {
    
  •   		ch = *m_src++;
    
  •   		if (ch != ' ' || last_read_was_not_a_blank) {
    
  •   				*m_dest = ch;
    
  •   				m_dest++;
    
  •   		}
    
  •   		last_read_was_not_a_blank = ch != ' ';
    
  •   }
    
  • for ( ; i < n; i++)
  •    dest[i] = '\0';
    
  •   return dest;
    

+}
+
/* exported for testing */
extern int
getline_from_buffer(char *readbuffer, char *linebuffer, int linebuflen)
@@ -184,7 +213,7 @@ getline_from_buffer(char *readbuffer, char *linebuffer, int linebuflen)

if (i != 0) {
	/* copy a line into the linebuffer */
  •   strncpy(linebuffer, readbuffer, (size_t) i);
    
  •   strncpy_trim_blanks(linebuffer, readbuffer, (size_t) i);
      /* sigh, null terminate */
      linebuffer[i] = '\0';
      /* shift the rest over; this could be done
    

--
2.37.2

-------8<------------------------------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant