Skip to content

Commit fddeddb

Browse files
fix(pdfixed): validate dev_id bounds in notification APIs (#1414)
Signed-off-by: Sanketjadhav31 <sj546400@gmail.com>
1 parent 5805891 commit fddeddb

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

pdfixed/src/pd_notifications.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ NotificationsListener *listeners[NUM_DEVICES];
144144
int pd_notifications_add_device(int dev_id, const char *notifications_addr,
145145
NotificationCb ageing_cb,
146146
NotificationCb learning_cb) {
147+
if (dev_id < 0 || dev_id >= NUM_DEVICES) {
148+
std::cerr << "Invalid device id " << dev_id << "\n";
149+
return -1;
150+
}
147151
assert(!listeners[dev_id]);
148152
listeners[dev_id] = new NotificationsListener(dev_id, notifications_addr);
149153
listeners[dev_id]->register_ageing_cb(ageing_cb);
@@ -153,6 +157,10 @@ int pd_notifications_add_device(int dev_id, const char *notifications_addr,
153157
}
154158

155159
int pd_notifications_remove_device(int dev_id) {
160+
if (dev_id < 0 || dev_id >= NUM_DEVICES) {
161+
std::cerr << "Invalid device id " << dev_id << "\n";
162+
return -1;
163+
}
156164
assert(listeners[dev_id]);
157165
delete listeners[dev_id];
158166
listeners[dev_id] = nullptr;

0 commit comments

Comments
 (0)