X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=chat%2Fchat.c;h=336c0f4995f4ab3dadd1612673d251ec0d3507d5;hp=f625a8a4fee521fdc3e6e13edc88dd3463675af6;hb=HEAD;hpb=956c492a1828bee383534fd6103c6e2a1a46a302 diff --git a/chat/chat.c b/chat/chat.c index f625a8a..788c42b 100644 --- a/chat/chat.c +++ b/chat/chat.c @@ -1,7 +1,32 @@ +/* SPDX-License-Identifier: MIT */ /* * Chat -- a program for automatic session establishment (i.e. dial * the phone and log in). * + * This version is Copyright 1995-2024 Paul Mackerras + * based on the original public-domain version by Karl Fox. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the “Software”), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * * Standard termination codes: * 0 - successful completion of the script * 1 - invalid argument, expect string too large, etc. @@ -11,7 +36,6 @@ * 5 - the second string declared as "ABORT" * 6 - ... and so on for successive ABORT strings. * - * This software is in the public domain. * * ----------------- * 22-May-99 added environment substitutuion, enabled with -E switch. @@ -182,7 +206,7 @@ int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0; int clear_abort_next = 0; char *report_string[MAX_REPORTS] ; -char report_buffer[256] ; +char report_buffer[4096] ; int n_reports = 0, report_next = 0, report_gathering = 0 ; int clear_report_next = 0; @@ -609,7 +633,7 @@ void terminate(int status) int c, rep_len; rep_len = strlen(report_buffer); - while (rep_len + 1 <= sizeof(report_buffer)) { + while (rep_len + 1 < sizeof(report_buffer)) { alarm(1); c = get_char(); alarm(0); @@ -1133,7 +1157,7 @@ int chat_send (register char *s) if (verbose) msgf("timeout set to %d seconds", timeout); - + free(s); return 0; } @@ -1247,8 +1271,11 @@ int write_char(int c) int put_string(register char *s) { + char *s1; quiet = 0; + s = clean(s, 1); + s1 = s; if (verbose) { if (quiet) @@ -1263,8 +1290,10 @@ int put_string(register char *s) register char c = *s++; if (c != '\\') { - if (!write_char (c)) + if (!write_char (c)) { + free(s1); return 0; + } continue; } @@ -1283,8 +1312,10 @@ int put_string(register char *s) break; default: - if (!write_char (c)) + if (!write_char (c)) { + free(s1); return 0; + } break; } checksigs(); @@ -1292,6 +1323,7 @@ int put_string(register char *s) alarm(0); alarmed = 0; + free(s1); return (1); } @@ -1336,10 +1368,10 @@ int get_string(register char *string) char temp[STR_LEN]; int c, printed = 0, len, minlen; register char *s = temp, *end = s + STR_LEN; - char *logged = temp; + char *s1, *logged = temp; fail_reason = (char *)0; - string = clean(string, 0); + string = s1 = clean(string, 0); len = strlen(string); minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1; @@ -1349,12 +1381,14 @@ int get_string(register char *string) if (len > STR_LEN) { msgf("expect string is too long"); exit_code = 1; + free(s1); return 0; } if (len == 0) { if (verbose) msgf("got it"); + free(s1); return (1); } @@ -1402,6 +1436,7 @@ int get_string(register char *string) strftime (report_buffer, 20, "%b %d %H:%M:%S ", tm_now); strcat (report_buffer, report_string[n]); + free(report_string[n]); report_string[n] = (char *) NULL; report_gathering = 1; break; @@ -1411,8 +1446,10 @@ int get_string(register char *string) else { if (!iscntrl (c)) { int rep_len = strlen (report_buffer); - report_buffer[rep_len] = c; - report_buffer[rep_len + 1] = '\0'; + if ((rep_len + 1) < sizeof(report_buffer)) { + report_buffer[rep_len] = c; + report_buffer[rep_len + 1] = '\0'; + } } else { report_gathering = 0; @@ -1431,6 +1468,7 @@ int get_string(register char *string) alarm(0); alarmed = 0; + free(s1); return (1); } @@ -1447,6 +1485,7 @@ int get_string(register char *string) alarmed = 0; exit_code = n + 4; strcpy(fail_reason = fail_buffer, abort_string[n]); + free(s1); return (0); } } @@ -1478,6 +1517,7 @@ int get_string(register char *string) exit_code = 3; alarmed = 0; + free(s1); return (0); }