aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/pop.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src/pop.c')
-rw-r--r--lib-src/pop.c79
1 files changed, 23 insertions, 56 deletions
diff --git a/lib-src/pop.c b/lib-src/pop.c
index c4c7f2b4e2f..74054e0e1b1 100644
--- a/lib-src/pop.c
+++ b/lib-src/pop.c
@@ -21,11 +21,7 @@ You should have received a copy of the GNU General Public License
21along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 21along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 22
23 23
24#ifdef HAVE_CONFIG_H
25#include <config.h> 24#include <config.h>
26#else
27#define MAIL_USE_POP
28#endif
29 25
30#ifdef MAIL_USE_POP 26#ifdef MAIL_USE_POP
31 27
@@ -101,7 +97,7 @@ extern char *krb_realmofhost (/* char * */);
101#endif /* KERBEROS */ 97#endif /* KERBEROS */
102 98
103#ifndef WINDOWSNT 99#ifndef WINDOWSNT
104#if !defined (HAVE_H_ERRNO) || !defined (HAVE_CONFIG_H) 100#ifndef HAVE_H_ERRNO
105extern int h_errno; 101extern int h_errno;
106#endif 102#endif
107#endif 103#endif
@@ -344,10 +340,7 @@ pop_stat (popserver server, int *count, int *size)
344 if (strncmp (fromserver, "+OK ", 4)) 340 if (strncmp (fromserver, "+OK ", 4))
345 { 341 {
346 if (0 == strncmp (fromserver, "-ERR", 4)) 342 if (0 == strncmp (fromserver, "-ERR", 4))
347 { 343 snprintf (pop_error, ERROR_MAX, "%s", fromserver);
348 strncpy (pop_error, fromserver, ERROR_MAX);
349 pop_error[ERROR_MAX-1] = '\0';
350 }
351 else 344 else
352 { 345 {
353 strcpy (pop_error, 346 strcpy (pop_error,
@@ -448,10 +441,7 @@ pop_list (popserver server, int message, int **IDs, int **sizes)
448 if (strncmp (fromserver, "+OK ", 4)) 441 if (strncmp (fromserver, "+OK ", 4))
449 { 442 {
450 if (! strncmp (fromserver, "-ERR", 4)) 443 if (! strncmp (fromserver, "-ERR", 4))
451 { 444 snprintf (pop_error, ERROR_MAX, "%s", fromserver);
452 strncpy (pop_error, fromserver, ERROR_MAX);
453 pop_error[ERROR_MAX-1] = '\0';
454 }
455 else 445 else
456 { 446 {
457 strcpy (pop_error, 447 strcpy (pop_error,
@@ -690,8 +680,7 @@ pop_multi_first (popserver server, const char *command, char **response)
690 680
691 if (0 == strncmp (*response, "-ERR", 4)) 681 if (0 == strncmp (*response, "-ERR", 4))
692 { 682 {
693 strncpy (pop_error, *response, ERROR_MAX); 683 snprintf (pop_error, ERROR_MAX, "%s", *response);
694 pop_error[ERROR_MAX-1] = '\0';
695 return (-1); 684 return (-1);
696 } 685 }
697 else if (0 == strncmp (*response, "+OK", 3)) 686 else if (0 == strncmp (*response, "+OK", 3))
@@ -864,8 +853,7 @@ pop_last (popserver server)
864 853
865 if (! strncmp (fromserver, "-ERR", 4)) 854 if (! strncmp (fromserver, "-ERR", 4))
866 { 855 {
867 strncpy (pop_error, fromserver, ERROR_MAX); 856 snprintf (pop_error, ERROR_MAX, "%s", fromserver);
868 pop_error[ERROR_MAX-1] = '\0';
869 return (-1); 857 return (-1);
870 } 858 }
871 else if (strncmp (fromserver, "+OK ", 4)) 859 else if (strncmp (fromserver, "+OK ", 4))
@@ -1065,9 +1053,8 @@ socket_connection (char *host, int flags)
1065 sock = socket (PF_INET, SOCK_STREAM, 0); 1053 sock = socket (PF_INET, SOCK_STREAM, 0);
1066 if (sock < 0) 1054 if (sock < 0)
1067 { 1055 {
1068 strcpy (pop_error, POP_SOCKET_ERROR); 1056 snprintf (pop_error, ERROR_MAX, "%s%s",
1069 strncat (pop_error, strerror (errno), 1057 POP_SOCKET_ERROR, strerror (errno));
1070 ERROR_MAX - sizeof (POP_SOCKET_ERROR));
1071 return (-1); 1058 return (-1);
1072 1059
1073 } 1060 }
@@ -1143,9 +1130,7 @@ socket_connection (char *host, int flags)
1143 if (! connect_ok) 1130 if (! connect_ok)
1144 { 1131 {
1145 CLOSESOCKET (sock); 1132 CLOSESOCKET (sock);
1146 strcpy (pop_error, CONNECT_ERROR); 1133 snprintf (pop_error, ERROR_MAX, "%s%s", CONNECT_ERROR, strerror (errno));
1147 strncat (pop_error, strerror (errno),
1148 ERROR_MAX - sizeof (CONNECT_ERROR));
1149 return (-1); 1134 return (-1);
1150 1135
1151 } 1136 }
@@ -1163,9 +1148,8 @@ socket_connection (char *host, int flags)
1163 krb5_auth_con_free (kcontext, auth_context); 1148 krb5_auth_con_free (kcontext, auth_context);
1164 if (kcontext) 1149 if (kcontext)
1165 krb5_free_context (kcontext); 1150 krb5_free_context (kcontext);
1166 strcpy (pop_error, KRB_ERROR); 1151 snprintf (pop_error, ERROR_MAX, "%s%s",
1167 strncat (pop_error, error_message (rem), 1152 KRB_ERROR, error_message (rem));
1168 ERROR_MAX - sizeof (KRB_ERROR));
1169 CLOSESOCKET (sock); 1153 CLOSESOCKET (sock);
1170 return (-1); 1154 return (-1);
1171 } 1155 }
@@ -1203,30 +1187,19 @@ socket_connection (char *host, int flags)
1203 krb5_free_principal (kcontext, server); 1187 krb5_free_principal (kcontext, server);
1204 if (rem) 1188 if (rem)
1205 { 1189 {
1206 strcpy (pop_error, KRB_ERROR); 1190 int pop_error_len = snprintf (pop_error, ERROR_MAX, "%s%s",
1207 strncat (pop_error, error_message (rem), 1191 KRB_ERROR, error_message (rem));
1208 ERROR_MAX - sizeof (KRB_ERROR));
1209#if defined HAVE_KRB5_ERROR_TEXT 1192#if defined HAVE_KRB5_ERROR_TEXT
1210 if (err_ret && err_ret->text.length) 1193 if (err_ret && err_ret->text.length)
1211 { 1194 {
1212 strncat (pop_error, " [server says '", 1195 int errlen = err_ret->text.length;
1213 ERROR_MAX - strlen (pop_error) - 1); 1196 snprintf (pop_error + pop_error_len, ERROR_MAX - pop_error_len,
1214 strncat (pop_error, err_ret->text.data, 1197 " [server says '.*%s']", errlen, err_ret->text.data);
1215 min (ERROR_MAX - strlen (pop_error) - 1,
1216 err_ret->text.length));
1217 strncat (pop_error, "']",
1218 ERROR_MAX - strlen (pop_error) - 1);
1219 } 1198 }
1220#elif defined HAVE_KRB5_ERROR_E_TEXT 1199#elif defined HAVE_KRB5_ERROR_E_TEXT
1221 if (err_ret && err_ret->e_text && strlen (*err_ret->e_text)) 1200 if (err_ret && err_ret->e_text && **err_ret->e_text)
1222 { 1201 snprintf (pop_error + pop_error_len, ERRMAX - pop_error_len,
1223 strncat (pop_error, " [server says '", 1202 " [server says '%s']", *err_ret->e_text);
1224 ERROR_MAX - strlen (pop_error) - 1);
1225 strncat (pop_error, *err_ret->e_text,
1226 ERROR_MAX - strlen (pop_error) - 1);
1227 strncat (pop_error, "']",
1228 ERROR_MAX - strlen (pop_error) - 1);
1229 }
1230#endif 1203#endif
1231 if (err_ret) 1204 if (err_ret)
1232 krb5_free_error (kcontext, err_ret); 1205 krb5_free_error (kcontext, err_ret);
@@ -1247,9 +1220,7 @@ socket_connection (char *host, int flags)
1247 free ((char *) ticket); 1220 free ((char *) ticket);
1248 if (rem != KSUCCESS) 1221 if (rem != KSUCCESS)
1249 { 1222 {
1250 strcpy (pop_error, KRB_ERROR); 1223 snprintf (pop_error, ERROR_MAX, "%s%s", KRB_ERROR, krb_err_txt[rem]);
1251 strncat (pop_error, krb_err_txt[rem],
1252 ERROR_MAX - sizeof (KRB_ERROR));
1253 CLOSESOCKET (sock); 1224 CLOSESOCKET (sock);
1254 return (-1); 1225 return (-1);
1255 } 1226 }
@@ -1354,9 +1325,8 @@ pop_getline (popserver server, char **line)
1354 server->buffer_size - server->data - 1, 0); 1325 server->buffer_size - server->data - 1, 0);
1355 if (ret < 0) 1326 if (ret < 0)
1356 { 1327 {
1357 strcpy (pop_error, GETLINE_ERROR); 1328 snprintf (pop_error, ERROR_MAX, "%s%s",
1358 strncat (pop_error, strerror (errno), 1329 GETLINE_ERROR, strerror (errno));
1359 ERROR_MAX - sizeof (GETLINE_ERROR));
1360 pop_trash (server); 1330 pop_trash (server);
1361 return (-1); 1331 return (-1);
1362 } 1332 }
@@ -1440,9 +1410,7 @@ sendline (popserver server, const char *line)
1440 if (ret < 0) 1410 if (ret < 0)
1441 { 1411 {
1442 pop_trash (server); 1412 pop_trash (server);
1443 strcpy (pop_error, SENDLINE_ERROR); 1413 snprintf (pop_error, ERROR_MAX, "%s%s", SENDLINE_ERROR, strerror (errno));
1444 strncat (pop_error, strerror (errno),
1445 ERROR_MAX - sizeof (SENDLINE_ERROR));
1446 return (ret); 1414 return (ret);
1447 } 1415 }
1448 1416
@@ -1504,8 +1472,7 @@ getok (popserver server)
1504 return (0); 1472 return (0);
1505 else if (! strncmp (fromline, "-ERR", 4)) 1473 else if (! strncmp (fromline, "-ERR", 4))
1506 { 1474 {
1507 strncpy (pop_error, fromline, ERROR_MAX); 1475 snprintf (pop_error, ERROR_MAX, "%s", fromline);
1508 pop_error[ERROR_MAX-1] = '\0';
1509 return (-1); 1476 return (-1);
1510 } 1477 }
1511 else 1478 else