alpine 3.8
integer weakness #4


Weakness Breakdown


An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.

Warning code(s):

Unless checked, the resulting number can exceed the expected range.

File Name:



The highlighted line of code below is the trigger point of this particular Alpine 3.8 integer weakness.


 * Processes an exit chunk from the server.  This is just a string
 * containing the exit code in decimal format.  It should fit well
 * within our buffer, so assume that it does.
 * @param len the current length of the buffer containing the exit code.
void processExit(char *buf, unsigned long len) {
  int exitcode;
  int bytesToRead = (BUFSIZE - 1 < len) ? BUFSIZE - 1 : len;
  int bytesRead = recv(nailgunsocket, buf, bytesToRead, MSG_WAITALL);

  if (bytesRead < 0) {

  buf[bytesRead] = 0;

  exitcode = atoi(buf);
  if (exitcode != 0) {
    exitcode = JRUBY_EXIT_EXCEPTION;


 * Sends len bytes from buf to the nailgun server in a stdin chunk.
 * @param buf the bytes to send
 * @param len the number of bytes to send
void sendStdin(char *buf, unsigned int len) {
  sendHeader(len, CHUNKTYPE_STDIN);
  sendAll(nailgunsocket, buf, len);

 * Sends a stdin-eof chunk to the nailgun server
void processEof() {
  sendHeader(0, CHUNKTYPE_STDIN_EOF);

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.