+* 2.2.82
+- Validate port number for forwarding
+== Jaewon Lim <jaewon81.lim@samsung.com> 2016-04-25
* 2.2.81
- Modify the location of log output for "sdb shell" routine.
- Add a secure warning message for pushing files.
-Version:2.2.81
+Version:2.2.82
Source:sdb
Maintainer:Kangho Kim <kh5325.kim@samsung.com>, Yoonki Park<yoonki.park@samsung.com>, Hyunsik Noh<hyunsik.noh@samsung.com>, Gun Kim<gune.kim@samsung.com>, Ho Namkoong<ho.namkoong@samsung.com>, Taeyoung Son<taeyoung2.son@samsung.com>
#include "sdb.h"
#include "sdb_messages.h"
#include "sdb_usb.h"
+#include "sockets.h"
static const char *SDK_TOOL_PATH="/home/developer/sdk_tools";
static const char *APP_PATH_PREFIX="/opt/apps";
if (verify_gdbserver_exist() < 0) {
return -1;
}
- if (port <= 0 || port > 65535) {
+ if (port <= 0 || port > MAX_PORT_NUMBER) {
print_error(SDB_MESSAGE_ERROR, ERR_GENERAL_LAUNCH_APP_FAIL, F(ERR_GENERAL_INVALID_PORT, port));
return -1;
#define A_VERSION 0x0100000
#define SDB_VERSION_MAJOR 2 // increments upon significant architectural changes or the achievement of important milestones
#define SDB_VERSION_MINOR 2 // progress is made within a major version
-#define SDB_VERSION_PATCH 81 // increments for small sets of changes
+#define SDB_VERSION_PATCH 82 // increments for small sets of changes
#define SDB_VERSION_MAX_LENGTH 128
int install_listener(int local_port, int connect_port, TRANSPORT* transport, LISTENER_TYPE ltype)
{
+ int fd = -1;
+ LISTENER* listener;
+
D("LN(%d)\n", local_port);
- LISTENER* listener = find_listener(local_port);
+ // check validness of local port number
+ if (local_port <= 0 || local_port > MAX_PORT_NUMBER) {
+ LOG_ERROR("can not install listener for port %d\n", local_port);
+ return -1;
+ }
+ listener = find_listener(local_port);
if(listener != NULL) {
if(listener->type != forwardListener) {
LOG_ERROR("can not repurpose if it is not forward listener");
return 0;
}
- //TODO REMOTE_DEVICE_CONNECT block remote connect until security issue is cleard
+ // TODO REMOTE_DEVICE_CONNECT block remote connect until security issue is cleared
// int fd = sdb_port_listen(INADDR_ANY, port, SOCK_STREAM);
- int fd = -1;
if(ltype == qemuListener || ltype == forwardListener || ltype == serverListener) {
fd = sdb_port_listen(INADDR_ANY, local_port, SOCK_STREAM);
}
int install_listener2(int local_port, char* connect_to, TRANSPORT* transport, LISTENER_TYPE ltype)
{
+ int fd = -1;
+ LISTENER* listener;
+
D("LN(%d)\n", local_port);
- LISTENER* listener = find_listener(local_port);
+ // check validness of local port number
+ if (local_port <= 0 || local_port > MAX_PORT_NUMBER) {
+ LOG_ERROR("can not install listener for port %d\n", local_port);
+ return -1;
+ }
+ listener = find_listener(local_port);
if(listener != NULL) {
if(listener->type != forwardListener) {
LOG_ERROR("can not repurpose if it is not forward listener");
return 0;
}
- //TODO REMOTE_DEVICE_CONNECT block remote connect until security issue is cleard
+ // TODO REMOTE_DEVICE_CONNECT block remote connect until security issue is cleared
// int fd = sdb_port_listen(INADDR_ANY, port, SOCK_STREAM);
- int fd = -1;
if(ltype == qemuListener || ltype == forwardListener || ltype == serverListener) {
fd = sdb_port_listen(INADDR_ANY, local_port, SOCK_STREAM);
}
// sdb_close(socket->fd);
}
+// return 0 if portstr is not valid port number
+// return 1 if portstr is valid port number
+static int is_valid_port(char* portstr) {
+ long port;
+ char* reststr;
+
+ errno = 0;
+ port = strtol(portstr, &reststr, 10);
+ if (errno != 0 || reststr[0] != '\0') {
+ // there is some character which is not number, so invalid port number
+ return 0;
+ }
+
+ if (port <= 0 || port > MAX_PORT_NUMBER) {
+ // only 1 ~ 65535 port number is available
+ return 0;
+ }
+
+ return 1;
+}
//TODO REMOTE_DEVICE_CONNECT
//const unsigned int unsigned_int_bit = sizeof(unsigned int) * 8;
forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_UNSUPPORT_TRANSMISSION_PROTOCOL, NULL);
goto sendfail;
}
+ if(!is_valid_port(remote + 4)) {
+ forward_err = error_message(SDB_MESSAGE_ERROR, F(ERR_GENERAL_INVALID_PORT, remote + 4), NULL);
+ goto sendfail;
+ }
if (t == NULL || t->connection_state == CS_OFFLINE) {
if(t != NULL) {
}
}
- if(strncmp("tcp:", local, 4)){
+ if(strncmp("tcp:", local, 4)) {
forward_err = error_message(SDB_MESSAGE_ERROR, ERR_FORWARD_UNSUPPORT_TRANSMISSION_PROTOCOL, NULL);
goto sendfail;
}
+ if(!is_valid_port(local + 4)) {
+ forward_err = error_message(SDB_MESSAGE_ERROR, F(ERR_GENERAL_INVALID_PORT, local + 4), NULL);
+ goto sendfail;
+ }
+
//if not tcp connect
// if(strncmp("tcp:", remote, 4)){
// if(!install_listener2(atoi(local + 4), remote, t, forwardListener)) {
#define REMOVE_SOCKET_STATUS(asocket, _status) ((asocket)->status &= ~(1 << _status))
#define HAS_SOCKET_STATUS(asocket, _status) ((asocket)->status & (1 << _status))
+#define MAX_PORT_NUMBER 65535
+
//TODO REMOTE_DEVICE_CONNECT
//extern const unsigned int unsigned_int_bit;
//extern const unsigned int remote_con_right_padding;
#define DEVICENAME_MAX 256
#define VMS_PATH OS_PATH_SEPARATOR_STR "vms" OS_PATH_SEPARATOR_STR
#define DEFAULT_DEVICENAME "<unknown>"
-#define SAFE_FREE(x) if ((x) != NULL) { free(x); x=NULL; }
+#define SAFE_FREE(x) if ((x) != NULL) { free((void*)(x)); x=NULL; }
#define SDB_MIN(a,b) \
({ __typeof__ (a) _a = (a); \