X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/a034d7e5edab2f0d56a62f6e1fcbbc76f3e5f31b..d4814561eafc238a9ed2b4fa67ef2755e5e83858:/sbr/fmt_scan.c diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 67f0a03e..cb29b72c 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -413,7 +413,10 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, struct fmt_callbacks *callbacks) { char *sp; - char *savestr, *str; + /* If str points to part of buffer[] or buffer2[] then it must only + * ever point at their first element as otherwise undefined + * behaviour from overlapping strncpy(3)s can result. */ + char *str, *savestr; char buffer[NMH_BUFSIZ], buffer2[NMH_BUFSIZ]; int i, c; bool rjust; @@ -757,6 +760,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, *xp-- = '\0'; if (rjust && i > 0 && (int) strlen(str) > i) str += strlen(str) - i; + str = memmove(buffer, str, strlen(str) + 1); } break; @@ -791,15 +795,18 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, value *= fmt->f_value; break; case FT_LV_DIVIDE_L: - if (fmt->f_value) - value /= fmt->f_value; - else + if (fmt->f_value == 0 || (fmt->f_value == -1 && value == INT_MIN)) { + // FIXME: Tell the user, and probably stop. value = 0; + } else { + value /= fmt->f_value; + } break; case FT_LV_MODULO_L: if (fmt->f_value) value %= fmt->f_value; else + // FIXME: Tell the user, and probably stop. value = 0; break; case FT_SAVESTR: @@ -946,6 +953,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, else break; } + str = memmove(buffer, str, strlen(str) + 1); } else if (!(str = get_x400_friendly (mn->m_mbox, buffer, sizeof(buffer)))) { unfriendly: