cn-uofbasel / ccn-lite

CCN-lite, a lightweight implementation of the CCNx protocol and its variations
ISC License
74 stars 63 forks source link

multiple(potential) issues in ccnl_cmp2int #309

Closed mfrey closed 5 years ago

mfrey commented 5 years ago

Description

The function ccnl_cmp2int in ccnl-pkt-util.c has multiple issues, i.e.

187 int
188 ccnl_cmp2int(unsigned char *cmp, int cmplen)
189 {
190     long int i;
191     char *str = (char *)ccnl_malloc(cmplen+1);
192     DEBUGMSG(DEBUG, "  inter a: %i\n", cmplen);
193     DEBUGMSG(DEBUG, "  inter b\n");
194     memcpy(str, (char *)cmp, cmplen);
195     str[cmplen] = '\0';
196     DEBUGMSG(DEBUG, "  inter c: %s\n", str);
197     i = strtol(str, NULL, 0);
198     DEBUGMSG(DEBUG, "  inter d\n");
199     ccnl_free(str);
200     return (int)i;
201 }

If cmplen is INT_MAX the computation in line 191 overflows and the actual allocated size is 0. Also, if a negative value (e.g. -1) is passed the size might be 0. In addition, if cmp is NULL the memcpy call will fail.