Skip to content
Snippets Groups Projects
Commit 9ab17ee4 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Don't egregiously use strlen() for ZRQ and OOII buffers.

We're building these one byte at a time, we know the length.
1.98s
parent 9132c351
No related branches found
No related tags found
No related merge requests found
Pipeline #7756 passed
...@@ -4117,6 +4117,7 @@ doterm(struct bbslist *bbs) ...@@ -4117,6 +4117,7 @@ doterm(struct bbslist *bbs)
BYTE zrqinit[] = {ZDLE, ZHEX, '0', '0', 0}; /* for Zmodem auto-downloads */ BYTE zrqinit[] = {ZDLE, ZHEX, '0', '0', 0}; /* for Zmodem auto-downloads */
BYTE zrinit[] = {ZDLE, ZHEX, '0', '1', 0}; /* for Zmodem auto-uploads */ BYTE zrinit[] = {ZDLE, ZHEX, '0', '1', 0}; /* for Zmodem auto-uploads */
BYTE zrqbuf[sizeof(zrqinit)]; BYTE zrqbuf[sizeof(zrqinit)];
size_t zrqlen;
int inch = NOINP; int inch = NOINP;
long double nextchar = 0; long double nextchar = 0;
long double lastchar = 0; long double lastchar = 0;
...@@ -4130,6 +4131,7 @@ doterm(struct bbslist *bbs) ...@@ -4130,6 +4131,7 @@ doterm(struct bbslist *bbs)
#ifndef WITHOUT_OOII #ifndef WITHOUT_OOII
BYTE ooii_buf[256]; BYTE ooii_buf[256];
size_t ooii_buf_len;
BYTE ooii_init1[] = BYTE ooii_init1[] =
"\xdb\b \xdb\b \xdb\b[\xdb\b[\xdb\b \xdb\bM\xdb\ba\xdb\bi\xdb\bn\xdb\bt\xdb\be\xdb\bn\xdb\ba\xdb\bn\xdb\bc\xdb\be\xdb\b \xdb\bC\xdb\bo\xdb\bm\xdb\bp\xdb\bl\xdb\be\xdb\bt\xdb\be\xdb\b \xdb\b]\xdb\b]\xdb\b \b\r\n\r\n\r\n\x1b[0;0;36mDo you have the Overkill Ansiterm installed? (y/N) \xe9 "; /* "\xdb\b \xdb\b \xdb\b[\xdb\b[\xdb\b \xdb\bM\xdb\ba\xdb\bi\xdb\bn\xdb\bt\xdb\be\xdb\bn\xdb\ba\xdb\bn\xdb\bc\xdb\be\xdb\b \xdb\bC\xdb\bo\xdb\bm\xdb\bp\xdb\bl\xdb\be\xdb\bt\xdb\be\xdb\b \xdb\b]\xdb\b]\xdb\b \b\r\n\r\n\r\n\x1b[0;0;36mDo you have the Overkill Ansiterm installed? (y/N) \xe9 "; /*
* *
...@@ -4199,8 +4201,10 @@ doterm(struct bbslist *bbs) ...@@ -4199,8 +4201,10 @@ doterm(struct bbslist *bbs)
cterm->music_enable = bbs->music; cterm->music_enable = bbs->music;
ch[1] = 0; ch[1] = 0;
zrqbuf[0] = 0; zrqbuf[0] = 0;
zrqlen = 0;
#ifndef WITHOUT_OOII #ifndef WITHOUT_OOII
ooii_buf[0] = 0; ooii_buf[0] = 0;
ooii_buf_len = 0;
#endif #endif
#ifdef WITH_JPEG_XL #ifdef WITH_JPEG_XL
if (cio_api.options & CONIO_OPT_SET_PIXEL) if (cio_api.options & CONIO_OPT_SET_PIXEL)
...@@ -4293,11 +4297,10 @@ doterm(struct bbslist *bbs) ...@@ -4293,11 +4297,10 @@ doterm(struct bbslist *bbs)
speedwatch = 0; speedwatch = 0;
break; break;
} }
j = strlen((char *)zrqbuf); if ((inch == zrqinit[zrqlen]) || (inch == zrinit[zrqlen])) {
if ((inch == zrqinit[j]) || (inch == zrinit[j])) { zrqbuf[zrqlen] = inch;
zrqbuf[j] = inch; zrqbuf[++zrqlen] = 0;
zrqbuf[++j] = 0; if (zrqlen == sizeof(zrqinit) - 1) {
if (j == sizeof(zrqinit) - 1) {
/* Have full sequence (Assumes /* Have full sequence (Assumes
* zrinit and zrqinit are same * zrinit and zrqinit are same
* length */ * length */
...@@ -4310,27 +4313,28 @@ doterm(struct bbslist *bbs) ...@@ -4310,27 +4313,28 @@ doterm(struct bbslist *bbs)
setup_mouse_events(&ms); setup_mouse_events(&ms);
suspend_rip(false); suspend_rip(false);
zrqbuf[0] = 0; zrqbuf[0] = 0;
zrqlen = 0;
remain = 1; remain = 1;
} }
} }
else { else {
zrqbuf[0] = 0; zrqbuf[0] = 0;
zrqlen = 0;
} }
#ifndef WITHOUT_OOII #ifndef WITHOUT_OOII
if (ooii_mode) { if (ooii_mode) {
if (ooii_buf[0] == 0) { if (ooii_buf[0] == 0) {
if (inch == 0xab) { if (inch == 0xab) {
ooii_buf[0] = inch; ooii_buf[ooii_buf_len++] = inch;
ooii_buf[1] = 0; ooii_buf[ooii_buf_len] = 0;
continue; continue;
} }
} }
else { /* Already have the start of the sequence */ else { /* Already have the start of the sequence */
j = strlen((char *)ooii_buf); if (ooii_buf_len + 1 >= sizeof(ooii_buf))
if (j + 1 >= sizeof(ooii_buf)) ooii_buf_len--;
j--; ooii_buf[ooii_buf_len++] = inch;
ooii_buf[j++] = inch; ooii_buf[ooii_buf_len] = 0;
ooii_buf[j] = 0;
if (inch == '|') { if (inch == '|') {
WRITE_OUTBUF(); WRITE_OUTBUF();
if (handle_ooii_code(ooii_buf, &ooii_mode, if (handle_ooii_code(ooii_buf, &ooii_mode,
...@@ -4343,38 +4347,41 @@ doterm(struct bbslist *bbs) ...@@ -4343,38 +4347,41 @@ doterm(struct bbslist *bbs)
conn_send(ansi_replybuf, conn_send(ansi_replybuf,
strlen((char *)ansi_replybuf), 0); strlen((char *)ansi_replybuf), 0);
ooii_buf[0] = 0; ooii_buf[0] = 0;
ooii_buf_len = 0;
} }
continue; continue;
} }
} }
else { else {
j = strlen((char *)ooii_buf); if (inch == ooii_init1[ooii_buf_len]) {
if (inch == ooii_init1[j]) { ooii_buf[ooii_buf_len++] = inch;
ooii_buf[j++] = inch; ooii_buf[ooii_buf_len] = 0;
ooii_buf[j] = 0; if (ooii_init1[ooii_buf_len] == 0) {
if (ooii_init1[j] == 0) {
if (strcmp((char *)ooii_buf, if (strcmp((char *)ooii_buf,
(char *)ooii_init1) == 0) { (char *)ooii_init1) == 0) {
ooii_mode = 1; ooii_mode = 1;
xptone_open(); xptone_open();
} }
ooii_buf[0] = 0; ooii_buf[0] = 0;
ooii_buf_len = 0;
} }
} }
else if (inch == ooii_init2[j]) { else if (inch == ooii_init2[ooii_buf_len]) {
ooii_buf[j++] = inch; ooii_buf[ooii_buf_len++] = inch;
ooii_buf[j] = 0; ooii_buf[ooii_buf_len] = 0;
if (ooii_init2[j] == 0) { if (ooii_init2[ooii_buf_len] == 0) {
if (strcmp((char *)ooii_buf, if (strcmp((char *)ooii_buf,
(char *)ooii_init2) == 0) { (char *)ooii_init2) == 0) {
ooii_mode = 2; ooii_mode = 2;
xptone_open(); xptone_open();
} }
ooii_buf[0] = 0; ooii_buf[0] = 0;
ooii_buf_len = 0;
} }
} }
else { else {
ooii_buf[0] = 0; ooii_buf[0] = 0;
ooii_buf_len = 0;
} }
} }
#endif /* ifndef WITHOUT_OOII */ #endif /* ifndef WITHOUT_OOII */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment