* src/sum.c (bsd_sum_stream): Detect overflow when updating length.
(sysv_sum_stream): Likewise.
checksum += buffer[i];
checksum &= 0xffff; /* Keep it within bounds. */
}
+ if (total_bytes + sum < total_bytes)
+ {
+ errno = EOVERFLOW;
+ goto cleanup_buffer;
+ }
total_bytes += sum;
}
checksum += buffer[i];
checksum &= 0xffff; /* Keep it within bounds. */
}
+ if (total_bytes + sum < total_bytes)
+ {
+ errno = EOVERFLOW;
+ goto cleanup_buffer;
+ }
total_bytes += sum;
memcpy (resstream, &checksum, sizeof checksum);
for (size_t i = 0; i < sum; i++)
s += buffer[i];
+ if (total_bytes + sum < total_bytes)
+ {
+ errno = EOVERFLOW;
+ goto cleanup_buffer;
+ }
total_bytes += sum;
}
for (size_t i = 0; i < sum; i++)
s += buffer[i];
+ if (total_bytes + sum < total_bytes)
+ {
+ errno = EOVERFLOW;
+ goto cleanup_buffer;
+ }
total_bytes += sum;
int r = (s & 0xffff) + ((s & 0xffffffff) >> 16);