report error when setting a too long port, do not silently truncate

This commit is contained in:
Marcus Meissner
2016-09-25 17:53:16 +02:00
parent 4950324701
commit f5940df96f

View File

@@ -208,6 +208,10 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
gp_port_set_timeout (port, 500);
break;
case GP_PORT_USB:
if (sizeof (port->settings.usb.port) <= strlen(info->path)) {
GP_LOG_E ("Path is too long for static buffer '%s'.", info->path);
return GP_ERROR_LIBRARY;
}
strncpy (port->settings.usb.port, info->path,
sizeof (port->settings.usb.port));
port->settings.usb.inep = -1;