PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_bgr(png_ptr);
png_bytep *row_pointers = malloc((size_t)(height * sizeof(png_bytep)));
+ if (row_pointers == NULL){
+ TRACE_ERROR("malloc failed");
+ png_destroy_write_struct(&png_ptr, (png_infopp)0);
+ free(png_buffer);
+ return -1;
+ }
int j = 0;
for (j = 0;j < height; j++)
row_pointers[j] = (png_bytep)(raw_data + (j * width * 4));
#include <common-adaptor.h>
#include <browser-provider-socket.h>
+// retry count to connect with provider
+#define BP_MAX_RETRY_COUNT 5
+// time in nano seconds approx 300 milli secs.
+#define BP_MAX_RETRY_DELAY 300000000
+
///////////// LOCAL APIs //////////////////
static int __adaptor_create_socket()
if (bp_ipc_send_custom_type(ipcinfo->cmd_socket, &cmd,
sizeof(bp_command_defs)) < 0 ||
bp_ipc_send_custom_type(ipcinfo->cmd_socket, &client_type,
- sizeof(bp_client_type_defs)) < 0 ||
- (errorcode = bp_ipc_read_errorcode(ipcinfo->cmd_socket)) != BP_ERROR_NONE ||
- (cid = bp_adaptor_ipc_read_int(ipcinfo->cmd_socket)) <= 0) {
- TRACE_ERROR("[CRITICAL] failed to connect with provider");
+ sizeof(bp_client_type_defs)) < 0) {
+ TRACE_ERROR("[CRITICAL] failed to send data to provider");
+ close(ipcinfo->cmd_socket);
+ free(ipcinfo);
+ ipcinfo = NULL;
+ usleep(50000);
+ return -1;
+ }
+ errorcode = bp_ipc_read_errorcode(ipcinfo->cmd_socket);
+ int retry_count = BP_MAX_RETRY_COUNT;
+ while((errorcode == BP_ERROR_IO_ERROR) && (errno == EINTR || errno == EAGAIN || errno == EINPROGRESS) && retry_count > 0) {
+ TRACE_ERROR("provider not alive, retry count [%d]", retry_count);
+ retry_count--;
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = BP_MAX_RETRY_DELAY;
+ nanosleep(&ts, NULL);
+ errorcode = bp_ipc_read_errorcode(ipcinfo->cmd_socket);
+ }
+ if (errorcode != BP_ERROR_NONE) {
+ TRACE_ERROR("[CRITICAL] failed to read errorcode from provider");
+ close(ipcinfo->cmd_socket);
+ free(ipcinfo);
+ ipcinfo = NULL;
+ usleep(50000);
+ return -1;
+ }
+ if ((cid = bp_adaptor_ipc_read_int(ipcinfo->cmd_socket)) <= 0) {
+ TRACE_ERROR("[CRITICAL] failed to read int from provider");
close(ipcinfo->cmd_socket);
free(ipcinfo);
ipcinfo = NULL;
// check buffer, this code will make crash by overflow
buffer =
(unsigned char *)calloc(byte_length, sizeof(unsigned char));
+ if (buffer == NULL) {
+ *errorcode = BP_ERROR_INVALID_PARAMETER;
+ return -1;
+ }
char *check_buffer = memcpy(buffer, value, byte_length);
if (check_buffer == NULL) {
TRACE_ERROR("[CHECK][%d] buffer:%d", cmd->id, length);
// check buffer, this code will make crash by overflow
unsigned char *buffer =
(unsigned char *)calloc(byte_length, sizeof(unsigned char));
+
+ if (buffer == NULL){
+ *errorcode = BP_ERROR_INVALID_PARAMETER;
+ return -1;
+ }
+
char *check_buffer = memcpy(buffer, value, byte_length);
if (check_buffer == NULL) {
TRACE_ERROR("[CHECK][%d] buffer:%d", cmd->id, length);
if (errorcode == SQLITE_OK) {
pbackup =
sqlite3_backup_init(backup_handle, "main", handle, "main");
+ if (pbackup == NULL) {
+ sqlite3_close(backup_handle);
+ TRACE_ERROR("[INIT]");
+ return -1;
+ }
do {
errorcode = sqlite3_backup_step(pbackup, -1);
TRACE_SECURE_INFO("progress (%d)",
if (errorcode == SQLITE_OK) {
pbackup =
sqlite3_backup_init(handle, "main", backup_handle, "main");
+ if (pbackup == NULL) {
+ sqlite3_close(backup_handle);
+ TRACE_ERROR("[INIT]");
+ return -1;
+ }
do {
errorcode = sqlite3_backup_step(pbackup, -1);
TRACE_SECURE_INFO("progress (%d)",
if (getbytes > 0) {
getstr = (char *)calloc(getbytes + 1, sizeof(char));
if (getstr != NULL) {
- memcpy(getstr, sqlite3_column_text(stmt, index),
- getbytes * sizeof(char));
- getstr[getbytes] = '\0';
+ char *gettext = NULL;
+ gettext = sqlite3_column_text(stmt, index);
+ if (gettext != NULL){
+ memcpy(getstr, gettext,
+ getbytes * sizeof(char));
+ getstr[getbytes] = '\0';
+ }
} else {
TRACE_ERROR("[CHECK] alloc for string");
}
fd_set rset, eset, listen_fdset, except_fdset;
struct timeval timeout; // for timeout of select
long flexible_timeout = BP_CARE_CLIENT_MAX_INTERVAL;
- int listenfd, clientfd, maxfd;
+ int listenfd, maxfd;
socklen_t clientlen;
struct sockaddr_un clientaddr;
unsigned i, is_timeout;
// initialize timeout structure for calling timeout exactly
memset(&timeout, 0x00, sizeof(struct timeval));
timeout.tv_sec = flexible_timeout;
- clientfd = -1;
is_timeout = 1;
rset = listen_fdset;
// Anyway accept client.
clientlen = sizeof(clientaddr);
- clientfd = accept(listenfd, (struct sockaddr *)&clientaddr,
+ int clientfd = accept(listenfd, (struct sockaddr *)&clientaddr,
&clientlen);
if (clientfd < 0) {
TRACE_ERROR("[CRITICAL] accept provider was crashed ?");
bp_ipc_send_custom_type(clientfd,
&privates->slots[i].client->cid, sizeof(int));
+ } else {
+ //Unknown case
+ close(clientfd);
}
} // New Connection
columns_index = 0;
if (offset & BP_TAB_O_INDEX) {
int *recvint = columns[columns_index].value;
- info.index = *recvint;
+ if (recvint != NULL)
+ info.index = *recvint;
columns_index++;
}
if (offset & BP_TAB_O_IS_ACTIVATED) {
int *recvint = columns[columns_index].value;
- info.is_activated = *recvint;
+ if (recvint != NULL)
+ info.is_activated = *recvint;
columns_index++;
}
if (offset & BP_TAB_O_IS_INCOGNITO) {
int *recvint = columns[columns_index].value;
- info.is_incognito = *recvint;
+ if (recvint != NULL)
+ info.is_incognito = *recvint;
columns_index++;
}
if (offset & BP_TAB_O_BROWSER_INSTANCE) {
int *recvint = columns[columns_index].value;
- info.browser_instance = *recvint;
+ if (recvint != NULL)
+ info.browser_instance = *recvint;
columns_index++;
}
if (offset & BP_TAB_O_DATE_CREATED) {
int *recvint = columns[columns_index].value;
- info.date_created = *recvint;
+ if (recvint != NULL)
+ info.date_created = *recvint;
columns_index++;
}
if (offset & BP_TAB_O_DATE_MODIFIED) {
int *recvint = columns[columns_index].value;
- info.date_modified = *recvint;
+ if (recvint != NULL)
+ info.date_modified = *recvint;
columns_index++;
}
BP_DB_COMMON_COL_DEVICE_ID, BP_DB_COL_TYPE_TEXT,
device_id, &errorcode);
TRACE_SECURE_DEBUG("[%d] current activated:%d device-id:%s", id,
- activated_id, device_id);
+ activated_id, device_id);
free(device_id);
if (activated_id == id) {
TRACE_ERROR("[ACTIVATE][%d] already activated", id);