summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Dan Dennedy 2008-07-06 12:06:40 -0700
committerGravatar Dan Dennedy 2008-07-06 12:06:40 -0700
commit8f942654d9c2b9cd957e8e1f7eb1f29a05bbf64a (patch)
tree3cdb6f52867ee18af06f7e478fcaa9e15e7a8510 /src/main.c
parentFix raw1394_read_cycle_timer after juju integration (diff)
Change handle validation to prevent segfault and be more informative.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 01b715a..55b4fbc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <netinet/in.h>
+#include <limits.h>
#include "raw1394.h"
#include "csr.h"
@@ -178,7 +179,11 @@ int ieee1394_get_fd(struct ieee1394_handle *handle)
unsigned int raw1394_get_generation(struct raw1394_handle *handle)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ errno = EINVAL;
+ return UINT_MAX;
+ }
+ if (handle->is_fw)
return handle->mode.fw->generation;
else
return handle->mode.ieee1394->generation;
@@ -186,7 +191,10 @@ unsigned int raw1394_get_generation(struct raw1394_handle *handle)
void raw1394_update_generation(struct raw1394_handle *handle, unsigned int gen)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ return;
+ }
+ if (handle->is_fw)
handle->mode.fw->generation = gen;
else
handle->mode.ieee1394->generation = gen;
@@ -194,22 +202,37 @@ void raw1394_update_generation(struct raw1394_handle *handle, unsigned int gen)
int ieee1394_get_nodecount(struct ieee1394_handle *handle)
{
- return handle->num_of_nodes;
+ if (!handle) {
+ errno = EINVAL;
+ return UINT_MAX;
+ }
+ return handle->num_of_nodes;
}
nodeid_t ieee1394_get_local_id(struct ieee1394_handle *handle)
{
- return handle->local_id;
+ if (!handle) {
+ errno = EINVAL;
+ return 0xFFFF;
+ }
+ return handle->local_id;
}
nodeid_t ieee1394_get_irm_id(struct ieee1394_handle *handle)
{
- return handle->irm_id;
+ if (!handle) {
+ errno = EINVAL;
+ return 0xFFFF;
+ }
+ return handle->irm_id;
}
void raw1394_set_userdata(struct raw1394_handle *handle, void *data)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ return;
+ }
+ if (handle->is_fw)
handle->mode.fw->userdata = data;
else
handle->mode.ieee1394->userdata = data;
@@ -217,7 +240,11 @@ void raw1394_set_userdata(struct raw1394_handle *handle, void *data)
void *raw1394_get_userdata(struct raw1394_handle *handle)
{
- if (handle && handle->is_fw)
+ if (!handle) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (handle->is_fw)
return handle->mode.fw->userdata;
else
return handle->mode.ieee1394->userdata;
@@ -503,4 +530,3 @@ int ieee1394_channel_modify (raw1394handle_t handle, unsigned int channel,
return 0;
}
-