diff options
| author | Paul Eggert | 2012-07-10 14:48:34 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-07-10 14:48:34 -0700 |
| commit | e99a530f8cdca3ccd9e739cd092ed9865d12fe89 (patch) | |
| tree | c2bef9f80ff9910be17757a83f61caed02146d0a /lib-src/pop.c | |
| parent | c59592b32f5b5808c12720bfd37ea73b473fa1db (diff) | |
| download | emacs-e99a530f8cdca3ccd9e739cd092ed9865d12fe89.tar.gz emacs-e99a530f8cdca3ccd9e739cd092ed9865d12fe89.zip | |
Simplify by avoiding confusing use of strncpy etc.
Diffstat (limited to 'lib-src/pop.c')
| -rw-r--r-- | lib-src/pop.c | 73 |
1 files changed, 22 insertions, 51 deletions
diff --git a/lib-src/pop.c b/lib-src/pop.c index b8ed65c3eac..74054e0e1b1 100644 --- a/lib-src/pop.c +++ b/lib-src/pop.c | |||
| @@ -340,10 +340,7 @@ pop_stat (popserver server, int *count, int *size) | |||
| 340 | if (strncmp (fromserver, "+OK ", 4)) | 340 | if (strncmp (fromserver, "+OK ", 4)) |
| 341 | { | 341 | { |
| 342 | if (0 == strncmp (fromserver, "-ERR", 4)) | 342 | if (0 == strncmp (fromserver, "-ERR", 4)) |
| 343 | { | 343 | snprintf (pop_error, ERROR_MAX, "%s", fromserver); |
| 344 | strncpy (pop_error, fromserver, ERROR_MAX); | ||
| 345 | pop_error[ERROR_MAX-1] = '\0'; | ||
| 346 | } | ||
| 347 | else | 344 | else |
| 348 | { | 345 | { |
| 349 | strcpy (pop_error, | 346 | strcpy (pop_error, |
| @@ -444,10 +441,7 @@ pop_list (popserver server, int message, int **IDs, int **sizes) | |||
| 444 | if (strncmp (fromserver, "+OK ", 4)) | 441 | if (strncmp (fromserver, "+OK ", 4)) |
| 445 | { | 442 | { |
| 446 | if (! strncmp (fromserver, "-ERR", 4)) | 443 | if (! strncmp (fromserver, "-ERR", 4)) |
| 447 | { | 444 | snprintf (pop_error, ERROR_MAX, "%s", fromserver); |
| 448 | strncpy (pop_error, fromserver, ERROR_MAX); | ||
| 449 | pop_error[ERROR_MAX-1] = '\0'; | ||
| 450 | } | ||
| 451 | else | 445 | else |
| 452 | { | 446 | { |
| 453 | strcpy (pop_error, | 447 | strcpy (pop_error, |
| @@ -686,8 +680,7 @@ pop_multi_first (popserver server, const char *command, char **response) | |||
| 686 | 680 | ||
| 687 | if (0 == strncmp (*response, "-ERR", 4)) | 681 | if (0 == strncmp (*response, "-ERR", 4)) |
| 688 | { | 682 | { |
| 689 | strncpy (pop_error, *response, ERROR_MAX); | 683 | snprintf (pop_error, ERROR_MAX, "%s", *response); |
| 690 | pop_error[ERROR_MAX-1] = '\0'; | ||
| 691 | return (-1); | 684 | return (-1); |
| 692 | } | 685 | } |
| 693 | else if (0 == strncmp (*response, "+OK", 3)) | 686 | else if (0 == strncmp (*response, "+OK", 3)) |
| @@ -860,8 +853,7 @@ pop_last (popserver server) | |||
| 860 | 853 | ||
| 861 | if (! strncmp (fromserver, "-ERR", 4)) | 854 | if (! strncmp (fromserver, "-ERR", 4)) |
| 862 | { | 855 | { |
| 863 | strncpy (pop_error, fromserver, ERROR_MAX); | 856 | snprintf (pop_error, ERROR_MAX, "%s", fromserver); |
| 864 | pop_error[ERROR_MAX-1] = '\0'; | ||
| 865 | return (-1); | 857 | return (-1); |
| 866 | } | 858 | } |
| 867 | else if (strncmp (fromserver, "+OK ", 4)) | 859 | else if (strncmp (fromserver, "+OK ", 4)) |
| @@ -1061,9 +1053,8 @@ socket_connection (char *host, int flags) | |||
| 1061 | sock = socket (PF_INET, SOCK_STREAM, 0); | 1053 | sock = socket (PF_INET, SOCK_STREAM, 0); |
| 1062 | if (sock < 0) | 1054 | if (sock < 0) |
| 1063 | { | 1055 | { |
| 1064 | strcpy (pop_error, POP_SOCKET_ERROR); | 1056 | snprintf (pop_error, ERROR_MAX, "%s%s", |
| 1065 | strncat (pop_error, strerror (errno), | 1057 | POP_SOCKET_ERROR, strerror (errno)); |
| 1066 | ERROR_MAX - sizeof (POP_SOCKET_ERROR)); | ||
| 1067 | return (-1); | 1058 | return (-1); |
| 1068 | 1059 | ||
| 1069 | } | 1060 | } |
| @@ -1139,9 +1130,7 @@ socket_connection (char *host, int flags) | |||
| 1139 | if (! connect_ok) | 1130 | if (! connect_ok) |
| 1140 | { | 1131 | { |
| 1141 | CLOSESOCKET (sock); | 1132 | CLOSESOCKET (sock); |
| 1142 | strcpy (pop_error, CONNECT_ERROR); | 1133 | snprintf (pop_error, ERROR_MAX, "%s%s", CONNECT_ERROR, strerror (errno)); |
| 1143 | strncat (pop_error, strerror (errno), | ||
| 1144 | ERROR_MAX - sizeof (CONNECT_ERROR)); | ||
| 1145 | return (-1); | 1134 | return (-1); |
| 1146 | 1135 | ||
| 1147 | } | 1136 | } |
| @@ -1159,9 +1148,8 @@ socket_connection (char *host, int flags) | |||
| 1159 | krb5_auth_con_free (kcontext, auth_context); | 1148 | krb5_auth_con_free (kcontext, auth_context); |
| 1160 | if (kcontext) | 1149 | if (kcontext) |
| 1161 | krb5_free_context (kcontext); | 1150 | krb5_free_context (kcontext); |
| 1162 | strcpy (pop_error, KRB_ERROR); | 1151 | snprintf (pop_error, ERROR_MAX, "%s%s", |
| 1163 | strncat (pop_error, error_message (rem), | 1152 | KRB_ERROR, error_message (rem)); |
| 1164 | ERROR_MAX - sizeof (KRB_ERROR)); | ||
| 1165 | CLOSESOCKET (sock); | 1153 | CLOSESOCKET (sock); |
| 1166 | return (-1); | 1154 | return (-1); |
| 1167 | } | 1155 | } |
| @@ -1199,30 +1187,19 @@ socket_connection (char *host, int flags) | |||
| 1199 | krb5_free_principal (kcontext, server); | 1187 | krb5_free_principal (kcontext, server); |
| 1200 | if (rem) | 1188 | if (rem) |
| 1201 | { | 1189 | { |
| 1202 | strcpy (pop_error, KRB_ERROR); | 1190 | int pop_error_len = snprintf (pop_error, ERROR_MAX, "%s%s", |
| 1203 | strncat (pop_error, error_message (rem), | 1191 | KRB_ERROR, error_message (rem)); |
| 1204 | ERROR_MAX - sizeof (KRB_ERROR)); | ||
| 1205 | #if defined HAVE_KRB5_ERROR_TEXT | 1192 | #if defined HAVE_KRB5_ERROR_TEXT |
| 1206 | if (err_ret && err_ret->text.length) | 1193 | if (err_ret && err_ret->text.length) |
| 1207 | { | 1194 | { |
| 1208 | strncat (pop_error, " [server says '", | 1195 | int errlen = err_ret->text.length; |
| 1209 | ERROR_MAX - strlen (pop_error) - 1); | 1196 | snprintf (pop_error + pop_error_len, ERROR_MAX - pop_error_len, |
| 1210 | strncat (pop_error, err_ret->text.data, | 1197 | " [server says '.*%s']", errlen, err_ret->text.data); |
| 1211 | min (ERROR_MAX - strlen (pop_error) - 1, | ||
| 1212 | err_ret->text.length)); | ||
| 1213 | strncat (pop_error, "']", | ||
| 1214 | ERROR_MAX - strlen (pop_error) - 1); | ||
| 1215 | } | 1198 | } |
| 1216 | #elif defined HAVE_KRB5_ERROR_E_TEXT | 1199 | #elif defined HAVE_KRB5_ERROR_E_TEXT |
| 1217 | if (err_ret && err_ret->e_text && strlen (*err_ret->e_text)) | 1200 | if (err_ret && err_ret->e_text && **err_ret->e_text) |
| 1218 | { | 1201 | snprintf (pop_error + pop_error_len, ERRMAX - pop_error_len, |
| 1219 | strncat (pop_error, " [server says '", | 1202 | " [server says '%s']", *err_ret->e_text); |
| 1220 | ERROR_MAX - strlen (pop_error) - 1); | ||
| 1221 | strncat (pop_error, *err_ret->e_text, | ||
| 1222 | ERROR_MAX - strlen (pop_error) - 1); | ||
| 1223 | strncat (pop_error, "']", | ||
| 1224 | ERROR_MAX - strlen (pop_error) - 1); | ||
| 1225 | } | ||
| 1226 | #endif | 1203 | #endif |
| 1227 | if (err_ret) | 1204 | if (err_ret) |
| 1228 | krb5_free_error (kcontext, err_ret); | 1205 | krb5_free_error (kcontext, err_ret); |
| @@ -1243,9 +1220,7 @@ socket_connection (char *host, int flags) | |||
| 1243 | free ((char *) ticket); | 1220 | free ((char *) ticket); |
| 1244 | if (rem != KSUCCESS) | 1221 | if (rem != KSUCCESS) |
| 1245 | { | 1222 | { |
| 1246 | strcpy (pop_error, KRB_ERROR); | 1223 | snprintf (pop_error, ERROR_MAX, "%s%s", KRB_ERROR, krb_err_txt[rem]); |
| 1247 | strncat (pop_error, krb_err_txt[rem], | ||
| 1248 | ERROR_MAX - sizeof (KRB_ERROR)); | ||
| 1249 | CLOSESOCKET (sock); | 1224 | CLOSESOCKET (sock); |
| 1250 | return (-1); | 1225 | return (-1); |
| 1251 | } | 1226 | } |
| @@ -1350,9 +1325,8 @@ pop_getline (popserver server, char **line) | |||
| 1350 | server->buffer_size - server->data - 1, 0); | 1325 | server->buffer_size - server->data - 1, 0); |
| 1351 | if (ret < 0) | 1326 | if (ret < 0) |
| 1352 | { | 1327 | { |
| 1353 | strcpy (pop_error, GETLINE_ERROR); | 1328 | snprintf (pop_error, ERROR_MAX, "%s%s", |
| 1354 | strncat (pop_error, strerror (errno), | 1329 | GETLINE_ERROR, strerror (errno)); |
| 1355 | ERROR_MAX - sizeof (GETLINE_ERROR)); | ||
| 1356 | pop_trash (server); | 1330 | pop_trash (server); |
| 1357 | return (-1); | 1331 | return (-1); |
| 1358 | } | 1332 | } |
| @@ -1436,9 +1410,7 @@ sendline (popserver server, const char *line) | |||
| 1436 | if (ret < 0) | 1410 | if (ret < 0) |
| 1437 | { | 1411 | { |
| 1438 | pop_trash (server); | 1412 | pop_trash (server); |
| 1439 | strcpy (pop_error, SENDLINE_ERROR); | 1413 | snprintf (pop_error, ERROR_MAX, "%s%s", SENDLINE_ERROR, strerror (errno)); |
| 1440 | strncat (pop_error, strerror (errno), | ||
| 1441 | ERROR_MAX - sizeof (SENDLINE_ERROR)); | ||
| 1442 | return (ret); | 1414 | return (ret); |
| 1443 | } | 1415 | } |
| 1444 | 1416 | ||
| @@ -1500,8 +1472,7 @@ getok (popserver server) | |||
| 1500 | return (0); | 1472 | return (0); |
| 1501 | else if (! strncmp (fromline, "-ERR", 4)) | 1473 | else if (! strncmp (fromline, "-ERR", 4)) |
| 1502 | { | 1474 | { |
| 1503 | strncpy (pop_error, fromline, ERROR_MAX); | 1475 | snprintf (pop_error, ERROR_MAX, "%s", fromline); |
| 1504 | pop_error[ERROR_MAX-1] = '\0'; | ||
| 1505 | return (-1); | 1476 | return (-1); |
| 1506 | } | 1477 | } |
| 1507 | else | 1478 | else |