ret = gethostname(hostname, sizeof(hostname));
if (ret < 0)
#endif
- strcpy(hostname, "unknown");
+ snprintf(hostname, sizeof(hostname), "%s", "unknown");
+
#if !defined _WIN32 && !defined ADB_HOST_ON_TARGET
ret = getlogin_r(username, sizeof(username));
if (ret < 0)
#endif
- strcpy(username, "unknown");
+ snprintf(username, sizeof(username), "%s", "unknown");
ret = snprintf(buf, len, " %s@%s", username, hostname);
if (ret >= (signed) len)
static void get_vendor_keys(struct listnode *list) {
const char *adb_keys_path;
- char keys_path[MAX_PAYLOAD_V1];
+ char keys_path[MAX_PAYLOAD_V1] = {0, };
char *path;
char *save;
struct stat buf;
D("Error getting user key filename");
return 0;
}
- strcat(path, ".pub");
+ strncat(path, ".pub", sizeof(path) - strlen(path) - 1);
file = load_file(path, (unsigned*) &ret);
if (!file) {
if(src_dir == NULL) {
pwd_flag = 1;
src_dir = strdup("./");
+ if(!src_dir)
+ return;
}
d = opendir(src_dir);
if(d == 0) {
- goto finalize;
+ if(pwd_flag) {
+ SAFE_FREE(src_dir);
+ }
+ return;
}
struct dirent* de;
struct stat statbuf;
}
finalize:
+ if(pwd_flag)
+ SAFE_FREE(src_dir);
closedir(d);
}
argc -= 2;
argv += 2;
while(argc-- > 0) {
- strcat(shell_cmd, " ");
+ strncat(shell_cmd, " ", sizeof(shell_cmd) - strlen(shell_cmd) - 1);
/* quote empty strings and strings with spaces */
int quote = (**argv == 0 || strchr(*argv, ' '));
if (quote)
- strcat(shell_cmd, "\"");
- strcat(shell_cmd, *argv++);
+ strncat(shell_cmd, "\"", sizeof(shell_cmd) - strlen(shell_cmd) - 1);
+ strncat(shell_cmd, *argv++, sizeof(shell_cmd) - strlen(shell_cmd) - 1);
if (quote)
- strcat(shell_cmd, "\"");
+ strncat(shell_cmd, "\"", sizeof(shell_cmd) - strlen(shell_cmd) - 1);
}
fd = sdb_connect(shell_cmd);
D("error: write failure during connection\n");
if(host_fd == 0) {
char buf[10];
- sprintf(buf, "%d", fd);
+ snprintf(buf, sizeof(buf), "%d", fd);
print_error(SDB_MESSAGE_ERROR, F(ERR_SYNC_WRITE_FAIL, buf),NULL);
}
else {
return 0;
}
-int sdb_higher_ver(int first, int middle, int last) {
-
- const char* VERSION_QUERY = "shell:rpm -q sdbd";
- D("query the sdbd version\n");
- int fd = sdb_connect(VERSION_QUERY);
-
- if(fd < 0) {
- D("fail to query the sdbd version\n");
- return fd;
- }
-
- char ver[PATH_MAX];
- int max_len = PATH_MAX;
- char* result_ptr = ver;
- int len;
-
- D("read sdb version\n");
- while(fd >= 0) {
- len = sdb_read(fd, result_ptr, max_len);
- if(len == 0) {
- break;
- }
-
- if(len < 0) {
- if(errno == EINTR) {
- continue;
- }
- break;
- }
- max_len -= len;
- result_ptr += len;
- fflush(stdout);
- }
-
- int version;
- char* ver_num = NULL;
-
- ver_num = strchr(ver, '-') + 1;
-
- char* null = NULL;
- null = strchr(ver_num, '-');
-
- if(null == NULL) {
- goto error;
- }
- *null = '\0';
-
- D("sdbd version: %s\n", ver_num);
-
- null = strchr(ver_num, '.');
- if(null == NULL) {
- goto error;
- }
-
- *null = '\0';
- version = atoi(ver_num);
- if(version > first) {
- return 1;
- }
- if(version < first) {
- return 0;
- }
- ver_num = ++null;
-
- null = strchr(ver_num, '.');
- if(null == NULL) {
- goto error;
- }
-
- version = atoi(ver_num);
- *null = '\0';
- if(version > middle) {
- return 1;
- }
- if(version < middle) {
- return 0;
- }
- ver_num = ++null;
-
- version = atoi(ver_num);
- if(version > last) {
- return 1;
- }
- return 0;
-
-error:
- LOG_ERROR("wrong version format %s", ver);
- return -1;
-}
-
#define SDB_FAILMSG_BUF_SIZE 255
int sdb_status_getfailmsg(int fd, int host_fd, char** pp_failmsg)
{
/* return verbose error string from last operation */
const char *sdb_error(void);
-/**
- * check sdbd version in the target.
- * returns true, if target version is higher then {first}.{middle}.{last}.
- * else, returns false.
- */
-int sdb_higher_ver(int first, int middle, int last);
-
/**
* check /usr/sbin/sdk_launch exists in the target.
* /usr/sbin/sdk_launch is included higher than sdbd 2.2.4
p->msg.command = A_OPEN;
p->msg.arg0 = s->local_id;
p->msg.data_length = len;
- strcpy((char*) p->data, destination);
+ snprintf((char *)p->data, sizeof(p->data), "%s", destination);
send_packet(p, s->transport);
put_apacket(p);
}
else{
local = strtok(request, ";");
remote = strtok(NULL , ";");
- if(remote == 0 || remote[1] == '\0') {
+ if(local == NULL || remote == NULL || remote[1] == '\0') {
forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_INVALID_PROTOCOL, NULL);
goto sendfail;
}
static __inline__ void wakeup_select(T_PACKET* t_packet) {
sdb_mutex_lock(&wakeup_select_lock, "wakeup_select");
- writex(fdevent_wakeup_send, &t_packet, sizeof(t_packet));
+ writex(fdevent_wakeup_send, &t_packet, sizeof(&t_packet));
sdb_mutex_unlock(&wakeup_select_lock, "wakeup_select");
}
register_transport(t);
/* tizen specific */
- sprintf(device_name, "device-%d",get_connected_device_count(kTransportUsb));
+ snprintf(device_name, sizeof(device_name), "device-%d",get_connected_device_count(kTransportUsb));
t->device_name = strdup(device_name);
}
s_strncpy(usb_serial, serial, sizeof(usb_serial));
} else {
if(!get_usb_device_serial_number(fd, usb_dev->iSerialNumber, usb_serial)) {
- strcpy(usb_serial, "unknown");
+ snprintf(usb_serial, sizeof(usb_serial), "%s", "unknown");
}
}
s_strncpy(usb->unique_node_path, node,
len = strlen(str);
utf8 = (char *)calloc(len+1, sizeof(char));
- strcpy(utf8, str);
+ snprintf(utf8, (len+1)*sizeof(char), "%s", str);
return utf8;
}