diff options
| -rw-r--r-- | hcid/storage.c | 11 | ||||
| -rw-r--r-- | tools/hcitool.c | 13 | 
2 files changed, 20 insertions, 4 deletions
| diff --git a/hcid/storage.c b/hcid/storage.c index 79ec11af..c5f5eaed 100644 --- a/hcid/storage.c +++ b/hcid/storage.c @@ -34,6 +34,7 @@  #include <stdio.h>  #include <errno.h> +#include <ctype.h>  #include <fcntl.h>  #include <unistd.h>  #include <malloc.h> @@ -166,7 +167,7 @@ int write_device_name(const bdaddr_t *local, const bdaddr_t *peer, const char *n  	char filename[PATH_MAX + 1], addr[18], str[249], *buf, *ptr;  	bdaddr_t bdaddr;  	struct stat st; -	int fd, pos, err = 0; +	int i, fd, pos, err = 0;  	ba2str(local, addr);  	snprintf(filename, PATH_MAX, "%s/%s/names", STORAGEDIR, addr); @@ -216,7 +217,13 @@ int write_device_name(const bdaddr_t *local, const bdaddr_t *peer, const char *n  		ftruncate(fd, 0);  	} -	list = list_add(list, peer, name, strlen(name) + 1); +	memset(str, 0, sizeof(str)); +	strncpy(str, name, 248); +	for (i = 0; i < 248 && str[i]; i++) +		if (!isprint(str[i])) +			str[i] = '.'; + +	list = list_add(list, peer, str, strlen(str) + 1);  	if (!list) {  		err = -EIO;  		goto unlock; diff --git a/tools/hcitool.c b/tools/hcitool.c index 210ab2ba..e6561feb 100644 --- a/tools/hcitool.c +++ b/tools/hcitool.c @@ -34,6 +34,7 @@  #include <stdio.h>  #include <errno.h> +#include <ctype.h>  #include <fcntl.h>  #include <unistd.h>  #include <stdlib.h> @@ -411,7 +412,7 @@ static void cmd_scan(int dev_id, int argc, char **argv)  	struct hci_dev_info di;  	struct hci_conn_info_req *cr;  	int extcls = 0, extinf = 0, extoui = 0; -	int i, opt, dd, cc, nc; +	int i, n, opt, dd, cc, nc;  	length  = 8;	/* ~10 seconds */  	num_rsp = 0; @@ -510,6 +511,10 @@ static void cmd_scan(int dev_id, int argc, char **argv)  					sizeof(name), name, 100000) < 0)  				strcpy(name, "n/a"); +			for (n = 0; n < 248 && name[n]; n++) +				if (!isprint(name[n])) +					name[n] = '.'; +  			printf("\t%s\t%s\n", addr, name);  			continue;  		} @@ -563,8 +568,12 @@ static void cmd_scan(int dev_id, int argc, char **argv)  					sizeof(name), name, 100000) < 0) {  				if (!nc)  					strcpy(name, "n/a"); -			} else +			} else { +				for (n = 0; n < 248 && name[n]; n++) +					if (!isprint(name[n])) +						name[n] = '.';  				nc = 0; +			}  		}  		printf("Device name:\t%s%s\n", name, nc ? " [cached]" : ""); | 
