alpine 3.7
integer weakness #26

2

Weakness Breakdown


Definition:

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:

libdbi-drivers/src/libdbi-drivers-0.9.0/drivers/ingres/dbd_ingres.c

Context:

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

 						p = *errmsg;
					if(p){
						memcpy(p+count, buf, n);
						p[n] = 0;
						count += n;
					}
				}
			}else
				break;
		}
	}else{
		if(errmsg) *errmsg = NULL;
		if(errno) *errno = 0;
	}
}


/* ---------- connections ---------- */

static int ingres_envoption_num(dbi_conn_t *conn, II_LONG id, char *name){
	IIAPI_SETENVPRMPARM setEPParm;
	const char *opt = dbi_conn_get_option(conn, name);

	if(opt){
		II_LONG val = atoi(opt);
		setEPParm.se_envHandle = envHandle;
		setEPParm.se_paramID = id;
		setEPParm.se_paramValue = &val;
		IIapi_setEnvParam(&setEPParm);
		return setEPParm.se_status == IIAPI_ST_SUCCESS;
	}
	return 1;
}

static int ingres_option_num(dbi_conn_t *conn, IIAPI_SETCONPRMPARM *psc, II_LONG id, char *name){
	IIAPI_STATUS status;
	const char *opt = dbi_conn_get_option(conn, name);
	
	if(opt){
		II_LONG val = atoi(opt);
		psc->sc_paramID = id;
		psc->sc_paramValue = &val; // works for Ingres 'long' and 'bool' types too, which are all int.
		IIapi_setConnectParam(psc);
		status = ingres_wait(&psc->sc_genParm);
		DEBUG_ERROR(psc->sc_genParm.gp_errorHandle);
		return status == IIAPI_ST_SUCCESS;
	}
	return 1;
}
 

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.