From b833c9891ebe77a50453b10e25c93c2e3258a58b Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Wed, 5 May 2021 17:16:26 +0300 Subject: [PATCH] fixes with incorrect data has been written to the port; --- src/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 861e6d7..ff96ffb 100644 --- a/src/main.c +++ b/src/main.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) /* main loop */ while(eport_read(stdin, msgbuf, msgbuflen) > 0) { opt = eport_ejabberd_msgread(msgbuf, msgbuflen, &m); - if(opt > 0) { + if(opt < 0) { abort_parsing: fprintf(stderr, "Error: message isn't valid.\nExiting.\n"); ssllib_free(); @@ -140,7 +140,7 @@ int main(int argc, char **argv) /* connect to IMAPs */ if(tls_connect(imap_host, imap_port, &connection)) { fprintf(stderr, "Error: unable to connect to IMAPs.\n"); - opt = -1; + opt = 0; } else { opt = imap_auth(&connection, &m); tls_close(&connection); @@ -152,7 +152,7 @@ int main(int argc, char **argv) /* connect to SMTPs */ if(tls_connect(smtp_host, smtp_port, &connection)) { fprintf(stderr, "Error: unable to connect to SMTPs.\n"); - opt = -1; + opt = 0; } else { opt = smtp_checkuser(&connection, &m, smtp_host); tls_close(&connection); @@ -164,7 +164,7 @@ int main(int argc, char **argv) case EJA_REMOVEUSER3: /* still aren't supported by the program */ fprintf(stderr, "Error: This type of message are not supported.\n"); - opt = -1; + opt = 0; break; case EJA_UNKNOWN: default: /* something goes wrong with message */ @@ -173,7 +173,10 @@ int main(int argc, char **argv) } /* finally, reply ... */ - eport_write(stdout, (char *)((int16_t *)&opt), sizeof(int16_t)); + opt = ((int16_t)opt << 8) | (((int16_t)opt >> 8) & 0xff); + eport_write(stdout, (char *)(&opt), sizeof(int16_t)); + /* clear the buffer */ + memset(msgbuf, 0, msgbuflen); } ssllib_free();