summaryrefslogtreecommitdiff
path: root/serial
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2009-04-24 10:25:20 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2009-04-24 16:46:22 +0300
commitf7e6b2cd75ed58daa888216dc186e266e4eebf42 (patch)
tree7b8a6fa55123533ffc6b1919e80872f81ef1d979 /serial
parentf59ea5e814ad90de7e7561d1dc30d2cd0bedb0e6 (diff)
downloadbluez-f7e6b2cd75ed58daa888216dc186e266e4eebf42.tar.gz
Fix bug on Serial.Connect which cause UUID-128 to be interpreted as channel.
strtol was generating a valid channel from the given UUID-128 and find_port would first check if the port channel matches the given pattern.
Diffstat (limited to 'serial')
-rw-r--r--serial/port.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/serial/port.c b/serial/port.c
index d371fa3f4..72025fdde 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -103,18 +103,19 @@ static struct serial_port *find_port(GSList *ports, const char *pattern)
{
GSList *l;
int channel;
+ char *endptr = NULL;
- channel = strtol(pattern, NULL, 10);
+ channel = strtol(pattern, &endptr, 10);
for (l = ports; l != NULL; l = l->next) {
struct serial_port *port = l->data;
char *uuid_str;
int ret;
- if (port->channel == channel)
+ if (port->uuid && !strcasecmp(port->uuid, pattern))
return port;
- if (port->uuid && !strcasecmp(port->uuid, pattern))
+ if (endptr && *endptr == '\0' && port->channel == channel)
return port;
if (port->dev && !strcmp(port->dev, pattern))
@@ -493,9 +494,13 @@ static DBusMessage *port_connect(DBusConnection *conn,
port = find_port(device->ports, pattern);
if (!port) {
- int channel = strtol(pattern, NULL, 10);
- if (channel < 1 || channel > 30)
+ char *endptr = NULL;
+ int channel;
+
+ channel = strtol(pattern, &endptr, 10);
+ if ((endptr && *endptr != '\0') || channel < 1 || channel > 30)
return does_not_exist(msg, "Does not match");
+
port = create_port(device, NULL, channel);
}