centos 6
integer weakness #1

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:

PyGreSQL-3.8.1/pgmodule.c

Context:

The highlighted line of code below is the trigger point of this particular Centos 6 integer weakness.

 		return NULL;
	}

	/* checks result status */
	switch (PQresultStatus(self->last_result))
	{
			long		num_rows;

			/* query succeeded */
		case PGRES_TUPLES_OK:	/* DQL: returns None (DB-SIG compliant) */
			self->result_type = RESULT_DQL;
			self->max_row = PQntuples(self->last_result);
			self->num_fields = PQnfields(self->last_result);
			Py_INCREF(Py_None);
			return Py_None;
		case PGRES_COMMAND_OK:	/* other requests */
		case PGRES_COPY_OUT:
		case PGRES_COPY_IN:
			self->result_type = RESULT_DDL;
			temp = PQcmdTuples(self->last_result);
			num_rows = -1;
			if (temp[0] != 0)
			{
				self->result_type = RESULT_DML;
				num_rows = atol(temp);
			}
			return PyInt_FromLong(num_rows);

			/* query failed */
		case PGRES_EMPTY_QUERY:
			PyErr_SetString(PyExc_ValueError, "empty query.");
			break;
		case PGRES_BAD_RESPONSE:
		case PGRES_FATAL_ERROR:
		case PGRES_NONFATAL_ERROR:
			PyErr_SetString(ProgrammingError, PQerrorMessage(self->pgcnx->cnx));
			break;
		default:
			PyErr_SetString(InternalError, "internal error: "
				"unknown result status.");
			break;
	}

	/* frees result and returns error */
	PQclear(self->last_result);
	self->last_result = NULL;
	self->result_type = RESULT_EMPTY;
	return NULL;
}
 

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.