Compare commits

...

3 Commits

Author SHA1 Message Date
Devon Gardner
7599cc37cd
Merge 9054993842 into deac7df80a 2024-09-12 19:42:12 +02:00
Devon Gardner
9054993842 fix(coverity/509227): tui stop_driver_ti() avoid underflow
Problem:
write() can return -1 but is cast to unsigned type causing coverity
to detect possible overflowed integer

Solution:
Perform check to ensure all negative values are captured rather than
just -1 before casting to unsigned type
2024-09-11 09:32:35 -04:00
Devon Gardner
5dad85b977 fix(coverity/509228): tui start_driver_ti() avoid underflow
Problem:
write() can return -1 but is cast to unsigned type causing coverity
to detect possible overflowed integer

Solution:
Perform check to ensure all negative values are captured rather than
just -1 before casting to unsigned type
2024-09-11 09:22:04 -04:00

View File

@ -410,10 +410,11 @@ int start_driver_ti(TermKey *tk, void *info)
// Can't call putp or tputs because they suck and don't give us fd control // Can't call putp or tputs because they suck and don't give us fd control
len = strlen(start_string); len = strlen(start_string);
while (len) { while (len) {
size_t written = (size_t)write(tk->fd, start_string, (unsigned)len); ssize_t result = write(tk->fd, start_string, (unsigned)len);
if (written == (size_t)-1) { if (result < 0) {
return 0; return 0;
} }
size_t written = (size_t)result;
start_string += written; start_string += written;
len -= written; len -= written;
} }
@ -448,10 +449,11 @@ int stop_driver_ti(TermKey *tk, void *info)
// Can't call putp or tputs because they suck and don't give us fd control // Can't call putp or tputs because they suck and don't give us fd control
len = strlen(stop_string); len = strlen(stop_string);
while (len) { while (len) {
size_t written = (size_t)write(tk->fd, stop_string, (unsigned)len); ssize_t result = write(tk->fd, stop_string, (unsigned)len);
if (written == (size_t)-1) { if (result < 0) {
return 0; return 0;
} }
size_t written = (size_t)result;
stop_string += written; stop_string += written;
len -= written; len -= written;
} }