Don't accept a NULL pointer as parameter
Immediately return an error instead of trying to pass the NULL pointer to the underlying open system call.
This commit is contained in:
parent
f87720dff9
commit
42f8e012b7
@ -181,10 +181,10 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
dc_serial_t *device = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
if (out == NULL || name == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
INFO (context, "Open: name=%s", name ? name : "");
|
||||
INFO (context, "Open: name=%s", name);
|
||||
|
||||
// Allocate memory.
|
||||
device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable);
|
||||
|
||||
@ -161,15 +161,15 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
dc_serial_t *device = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
if (out == NULL || name == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
INFO (context, "Open: name=%s", name ? name : "");
|
||||
INFO (context, "Open: name=%s", name);
|
||||
|
||||
// Build the device name.
|
||||
const char *devname = NULL;
|
||||
char buffer[MAX_PATH] = "\\\\.\\";
|
||||
if (name && strncmp (name, buffer, 4) != 0) {
|
||||
if (strncmp (name, buffer, 4) != 0) {
|
||||
size_t length = strlen (name) + 1;
|
||||
if (length + 4 > sizeof (buffer))
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user