You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
compiling misdnuser with gcc 11.2.0 two functions throw array subscript bound errors. Perhaps false positives, perhaps not:
>>>
In file included from misc/mbuffer.c:21:
misc/mbuffer.c: In function ‘alloc_mbuffer’:
../include/mISDN/mbuffer.h:161:14: error: array subscript ‘struct mbuffer[0]’ is partly outside array bounds of ‘struct mqueue[1]’ [-Werror=array-bounds]
161 | next = prev->next;
| ~~~~~~~^~~~~~~~~~~~
misc/mbuffer.c:25:25: note: while referencing ‘free_queue_l2’
25 | static struct mqueue free_queue_l2, free_queue_l3;
<<<
by changing in this function like this:
prev = (struct mbuffer *)q->prev;
next = (struct mbuffer *)q->next;
the error disappears but not sure whether functionality is still correct. All the prev and next in both queue and buffer is rather confusing without an idea how this is supposed to function.
>>>
bridge.c: In function ‘ph_control’:
bridge.c:160:9: error: array subscript 2 is outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
160 | *d++ = c2;
| ^~~~
bridge.c:150:23: note: while referencing ‘data’
150 | unsigned char data[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
<<<
by adding 8, like:
unsigned char data[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)+8];
the error disappears but again not sure whether this is changing the intended behaviour.
The text was updated successfully, but these errors were encountered:
regarding misc/mbuffer.c have rewritten it after some study of the mbuffer and mqueue usage and the casting of the mqueue to mbuffer type. I think, but confirmation is needed, that following code does the same but does not evoke the compiler array bound protest.
static inline struct mbuffer *mdequeue(struct mqueue *q)
{
struct mbuffer *next, *prev, *result;
pthread_mutex_lock(&q->lock);
prev = (struct mbuffer *)q;
next = q->next; <=== q->next points at the same as original code's prev->next after type cast
result = NULL;
if (next != prev) {
result = next;
next = next->next;
q->len--;
next->prev = prev;
q->next = next; <=== q->next still points at the same as original code's prev->next
result->list = NULL;
}
pthread_mutex_unlock(&q->lock);
return result;
}
compiling misdnuser with gcc 11.2.0 two functions throw array subscript bound errors. Perhaps false positives, perhaps not:
>>>
In file included from misc/mbuffer.c:21:
misc/mbuffer.c: In function ‘alloc_mbuffer’:
../include/mISDN/mbuffer.h:161:14: error: array subscript ‘struct mbuffer[0]’ is partly outside array bounds of ‘struct mqueue[1]’ [-Werror=array-bounds]
161 | next = prev->next;
| ~~~~~~~^~~~~~~~~~~~
misc/mbuffer.c:25:25: note: while referencing ‘free_queue_l2’
25 | static struct mqueue free_queue_l2, free_queue_l3;
<<<
by changing in this function like this:
prev = (struct mbuffer *)q->prev;
next = (struct mbuffer *)q->next;
the error disappears but not sure whether functionality is still correct. All the prev and next in both queue and buffer is rather confusing without an idea how this is supposed to function.
>>>
bridge.c: In function ‘ph_control’:
bridge.c:160:9: error: array subscript 2 is outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
160 | *d++ = c2;
| ^~~~
bridge.c:150:23: note: while referencing ‘data’
150 | unsigned char data[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
<<<
by adding 8, like:
unsigned char data[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)+8];
the error disappears but again not sure whether this is changing the intended behaviour.
The text was updated successfully, but these errors were encountered: