aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2016-05-27 14:29:52 +0200
committerUwe Hermann <uwe@hermann-uwe.de>2016-05-27 14:45:26 +0200
commit39fcfdc9dae5311617f0e72b0a7333a199620190 (patch)
treecd6c303b4928f662b3b74d41119e6e2169eb8ebf
parent43376f3324cddd257a0260b06d9db8180c35fdf3 (diff)
std_scan_complete(): Catch some errors to avoid segfaults.
Check some variables for NULL before dereference to avoid segfaults due to buggy drivers (and show error messages so these issues are noticed early).
-rw-r--r--src/std.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/std.c b/src/std.c
index 4af3c68..fa668a7 100644
--- a/src/std.c
+++ b/src/std.c
@@ -378,18 +378,29 @@ SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di)
* }
* @endcode
*
- * @param di The driver instance to use.
+ * @param di The driver instance to use. Must not be NULL.
* @param devices List of newly discovered devices (struct sr_dev_inst).
*
* @return The @p devices list.
*/
SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices)
{
- struct drv_context *drvc = di->context;
+ struct drv_context *drvc;
GSList *l;
+ if (!di) {
+ sr_err("Invalid driver instance (di), cannot complete scan.");
+ return NULL;
+ }
+
+ drvc = di->context;
+
for (l = devices; l; l = l->next) {
struct sr_dev_inst *sdi = l->data;
+ if (!sdi) {
+ sr_err("Invalid driver instance, cannot complete scan.");
+ return NULL;
+ }
sdi->driver = di;
}