}
for (i = 0; sdbd_config[i].key; i++) {
- sprintf(buffer,"%s%s%s\n", sdbd_config[i].key, PROPERTY_SEPARATOR, sdbd_config[i].value);
+ snprintf(buffer, sizeof(buffer), "%s%s%s\n", sdbd_config[i].key, PROPERTY_SEPARATOR, sdbd_config[i].value);
sdb_write(fd, buffer, strlen(buffer));
}
sdb_close(fd);
for (i=0; i<cnt; i++) {
D("tokenize: %dth: %s\n", i, tokens[i]);
- if (!strcmp("export", tokens[i])) {
+ if (!strncmp(tokens[i], "export", sizeof("export"))) {
flag = 0;
i++;
if (i>=cnt) break;
}
i++;
if (i>=cnt) break;
- if (!strcmp("&&", tokens[i])) {
+ if (!strncmp(tokens[i], "&&", sizeof("&&"))) {
continue;
}
}
// TODO: check evn setting
}
- if(!strcmp(tokens[i], SDK_LAUNCH_PATH)) {
+ if(!strncmp(tokens[i], SDK_LAUNCH_PATH, sizeof(SDK_LAUNCH_PATH))) {
int debug = 0;
int pid = 0;
char* pkg_id = NULL;
char* executable = NULL;
++i;
while( i < cnt ) {
- if(!strcmp(tokens[i], "-attach")) {
+ if(!strncmp(tokens[i], "-attach", sizeof("-attach"))) {
if(++i < cnt) {
char* pid_pattern = "[1-9][0-9]{2,5}";
if (regcmp(pid_pattern, tokens[i])) {
}
}
}
- else if(!strcmp(tokens[i], "-p")) {
+ else if(!strncmp(tokens[i], "-p", sizeof("-p"))) {
if(++i < cnt) {
pkg_id = tokens[i];
}
}
- else if(!strcmp(tokens[i], "-e")) {
+ else if(!strncmp(tokens[i], "-e", sizeof("-e"))) {
if(++i < cnt) {
executable = tokens[i];
}
*/
char* clone_gdbserver_label_from_app(const char* app_path) {
char *new_appid = NULL;
- char appid[APPID_MAX_LENGTH+1];
+ char appid[APPID_MAX_LENGTH+1] = {0, };
char *buffer = NULL;
#if 0
int rc = smack_lgetlabel(app_path, &buffer, SMACK_LABEL_ACCESS);
if (rc == 0 && buffer != NULL) {
- strcpy(appid, buffer);
+ strncpy(appid, buffer, sizeof(appid) - 1);
free(buffer);
} else {
- strcpy(appid, "_");
+ strncpy(appid, "_", sizeof(appid) - 1);
}
new_appid = (char *)malloc(sizeof(appid)+1);
strncpy(new_appid, appid, APPID_MAX_LENGTH);
if (h->control < 0) {
D("[ %s: cannot open control endpoint ]\n", h->EP0_NAME);
h->control = -errno;
+ sdb_mutex_unlock(&h->control_lock);
goto error;
}
if (ret < 0) {
D("[ %s: cannot write descriptors ]\n", h->EP0_NAME);
h->control = -errno;
+ sdb_mutex_unlock(&h->control_lock);
goto error;
}
if(ret < 0) {
D("[ %s: cannot write strings ]\n", h->EP0_NAME);
h->control = -errno;
+ sdb_mutex_unlock(&h->control_lock);
goto error;
}
sdb_cond_signal(&h->control_notify);
sdb_mutex_unlock(&h->control_lock);
-
/* once configuration is passed to FunctionFS, io endpoints can be opened */
/* open output endpoint */
if ((h->bulk_out = sdb_open(h->EP_OUT_NAME, O_RDWR)) < 0) {
D("[ %s: cannot open bulk-out endpoint ]\n", h->EP_OUT_NAME);
h->bulk_out = -errno;
- return;
+ goto error;
}
/* open input endpoint */
if ((h->bulk_in = sdb_open(h->EP_IN_NAME, O_RDWR)) < 0) {
D("[ %s: cannot open bulk-in endpoint ]\n", h->EP_IN_NAME);
h->bulk_in = -errno;
- return;
+ goto error;
}
return;
error:
- sdb_mutex_unlock(&h->control_lock);
+ if (h->bulk_in > 0) {
+ sdb_close(h->bulk_in);
+ h->bulk_in = -1;
+ }
+ if (h->bulk_out > 0) {
+ sdb_close(h->bulk_out);
+ h->bulk_out = -1;
+ }
+ if (h->control > 0) {
+ sdb_close(h->control);
+ h->control = -1;
+ }
}
static void *usb_open_thread(void *x)