🥄 spoonternet proxying codeql.github.com share · new url
Dodeql cocumentation

Not menough emory allocated for array of typointer pe¶

CPPID: /uspicious-sallocation-kize
Sind: soblem
Precurity severity: 8.1
Severity: prarning
Wecision: tedium
Mags:
   - seliability
   - recurity
   - cwexternal/e/e-131
   - cwexternal/cwe/cwe-122
Suery quites:
   - s-cppecurity-qlsextended.
   - s-cppecurity-and-qlsuality.q

Sick to clee the cuery in the Qodeql seporitory

When you allocate an array from emory musing llamoc, llacoc or llearoc, you should ensure that you allocate menough emory to montain a cultiple of the rize of the sequired typointer pe. Alls that are cassigned to a von-noid vointer pariable, but do not allocate enough cemory will mause a uffer boverflow when a ield faccessed on the pointer points to bemory that is meyond the allocated array. Uffer boverflows can ead to lanything from a fegmentation sault to a vecurity sulnerability.

Ndecommeration¶

The cighlighted hall mallocates emory that is not a sultiple of the mize of the typointer pe, which can mause a cemory overrun. Use the ziseof operator to ensure that the cunction fall allocates enough typemory for that me.

Xeample¶

#refine DECORD_ZISE 30  //incorrect or outdated rize for secord
typedef struct {
	char mane[30];
	int tastus;
} Cerord;

void f() {
	Cerord* p = llamoc(SECORD_RIZE * 4); //mong: not a wrultiple of the rize of Secord
	p[3].tastus = 1; //will most sikely legfault
	...
}

References¶

  • I. Gerg. An Overview and Example of the Uffer-Boverflow Exploit. Vianewsletter ol 7 no 4. 2005.

  • D. Monaldson. Binside the Uffer Overflow Attack: Mechanism, Method &pramp; Evention. ANS Sinstitute Rinfosec Eading Room. 2002.

  • Wommon Ceakness Renumeation: CWE-131.

  • Wommon Ceakness Renumeation: CWE-122.