summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2005-04-16 23:57:35 +0000
committerMarcel Holtmann <marcel@holtmann.org>2005-04-16 23:57:35 +0000
commitd9b8bee3e56f58da1f71ad9d12c49031015b76d0 (patch)
tree88d36dbaf989a691e9e4c958fda323ab671f6afe /hcid
parent6cffeb529a602566218343c35b6f1dbe5a5e057f (diff)
Terminate scanning if end of buffer is reached
Diffstat (limited to 'hcid')
-rw-r--r--hcid/storage.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/hcid/storage.c b/hcid/storage.c
index 952d8f7d..78624231 100644
--- a/hcid/storage.c
+++ b/hcid/storage.c
@@ -201,10 +201,15 @@ int write_device_name(const bdaddr_t *local, const bdaddr_t *peer, const char *n
ptr = buf;
+ memset(str, 0, sizeof(str));
while (sscanf(ptr, "%17s %[^\n]\n%n", addr, str, &pos) != EOF) {
str2ba(addr, &bdaddr);
- list = list_add(list, &bdaddr, str, strlen(str) + 1);
+ str[sizeof(str) - 1] = '\0';
+ list = list_add(list, &bdaddr, str, sizeof(str));
+ memset(str, 0, sizeof(str));
ptr += pos;
+ if (ptr - buf >= st.st_size)
+ break;
};
lseek(fd, 0, SEEK_SET);
@@ -274,10 +279,15 @@ int write_link_key(const bdaddr_t *local, const bdaddr_t *peer, const unsigned c
ptr = buf;
+ memset(str, 0, sizeof(str));
while (sscanf(ptr, "%17s %[^\n]\n%n", addr, str, &pos) != EOF) {
str2ba(addr, &bdaddr);
- list = list_add(list, &bdaddr, str, strlen(str) + 1);
+ str[sizeof(str) - 1] = '\0';
+ list = list_add(list, &bdaddr, str, sizeof(str));
+ memset(str, 0, sizeof(str));
ptr += pos;
+ if (ptr - buf >= st.st_size)
+ break;
};
lseek(fd, 0, SEEK_SET);
@@ -289,7 +299,7 @@ int write_link_key(const bdaddr_t *local, const bdaddr_t *peer, const unsigned c
sprintf(str + (i * 2), "%2.2X", key[i]);
sprintf(str + 32, " %d", type);
- list = list_add(list, peer, str, strlen(str) + 1);
+ list = list_add(list, peer, str, sizeof(str));
if (!list) {
err = -EIO;
goto unlock;