replace strerror to strerror_r for security 09/46309/1 tizen_3.0.m1_mobile tizen_3.0.m1_tv accepted/tizen/mobile/20150819.235708 accepted/tizen/tv/20150819.235734 accepted/tizen/wearable/20150819.235803 submit/tizen/20150819.094203 submit/tizen_common/20151023.083358 submit/tizen_common/20151026.085049 tizen_3.0.m1_mobile_release tizen_3.0.m1_tv_release
authorHyunjun Ko <zzoon.ko@samsung.com>
Tue, 11 Aug 2015 05:16:39 +0000 (14:16 +0900)
committerSangkyu Park <sk1122.park@samsung.com>
Wed, 19 Aug 2015 05:54:01 +0000 (14:54 +0900)
Change-Id: I75a2a7d1c09cf2646f14a97bb10a99f8267db3ef

miracast_server/miracast_server_impl.c
src/scmirroring_src.c

index c750ca9adac0a7d789094352d27448e4782077c7..03e433958f267ecc240a156a8e2b31e730ba1ba6 100644 (file)
@@ -202,7 +202,9 @@ int __miracast_server_send_resp(MiracastServer *server, const gchar *cmd)
        _cmd[strlen(_cmd)] = '\0';
 
        if (write(client_sock, _cmd, strlen(_cmd) + 1) != ((int)(strlen(_cmd) + 1))) {
-               scmirroring_error("sendto failed [%s]", strerror(errno));
+               char buf[255] = {0, };
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("sendto failed [%s]", buf);
                ret = SCMIRRORING_ERROR_INVALID_OPERATION;
        } else {
                scmirroring_debug("Sent response [%s] successfully", _cmd);
@@ -354,10 +356,12 @@ static gboolean __miracast_server_ready_channel(int *sockfd)
        int i;
        gboolean bind_success = FALSE;
        struct sockaddr_un serv_addr;
+       char buf[255] = {0, };
 
        /* Create a TCP socket */
        if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
-               scmirroring_error("socket failed: %s", strerror(errno));
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("socket failed: %s", buf);
                return FALSE;
        }
 
@@ -377,7 +381,8 @@ static gboolean __miracast_server_ready_channel(int *sockfd)
        }
 
        if (bind_success == false) {
-               scmirroring_error("bind failed : %s %d_", strerror(errno), errno);
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("bind failed : %s %d_", buf, errno);
                close(sock);
                return FALSE;
        }
@@ -386,16 +391,21 @@ static gboolean __miracast_server_ready_channel(int *sockfd)
 
        /* Listening */
        if (listen(sock, SOMAXCONN) < 0) {
-               scmirroring_error("listen failed : %s", strerror(errno));
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("listen failed : %s", buf);
                close(sock);
                return FALSE;
        }
 
        /*change permission of sock file*/
-       if (chmod(MEDIA_IPC_PATH, 0770) < 0)
-               scmirroring_error("chmod failed [%s]", strerror(errno));
-       if (chown(MEDIA_IPC_PATH, 200, 5000) < 0)
-               scmirroring_error("chown failed [%s]", strerror(errno));
+       if (chmod(MEDIA_IPC_PATH, 0770) < 0) {
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("chmod failed [%s]", buf);
+       }
+       if (chown(MEDIA_IPC_PATH, 200, 5000) < 0) {
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("chown failed [%s]", buf);
+       }
 
        scmirroring_debug("Listening...");
        *sockfd = sock;
@@ -732,7 +742,9 @@ int __miracast_server_accept(int serv_sock, int *client_sock)
 
        client_addr_len = sizeof(client_addr);
        if ((sockfd = accept(serv_sock, (struct sockaddr *)&client_addr, &client_addr_len)) < 0) {
-               scmirroring_error("accept failed : %s", strerror(errno));
+               char buf[255] = {0, };
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("accept failed : %s", buf);
                *client_sock  = -1;
                return SCMIRRORING_ERROR_INVALID_OPERATION;
        }
@@ -813,7 +825,9 @@ gboolean __miracast_server_read_cb(GIOChannel *src,
        GIOChannel *channel = NULL;
        channel = g_io_channel_unix_new(client_sock);
        if (channel == NULL) {
-               scmirroring_error("g_io_channel_unix_new failed: %s", strerror(errno));
+               char buf[255] = {0, };
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("g_io_channel_unix_new failed: %s", buf);
        }
 
        /* Create new channel to watch udp socket */
index 1bb8d180f82c675a22fe97206a0c277e3a2823e8..c78b217aa69ea62e35ab9c748dcfd9b0b290ed91 100755 (executable)
@@ -72,7 +72,9 @@ static int __scmirroring_src_send_cmd_to_server(scmirroring_src_s *scmirroring,
        _cmd[strlen(_cmd)] = '\0';
 
        if (write(scmirroring->sock, _cmd, strlen(_cmd) + 1) != (signed int) strlen(_cmd) + 1) {
-               scmirroring_error("sendto failed [%s]", strerror(errno));
+               char buf[255] = {0, };
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("sendto failed [%s]", buf);
                ret = SCMIRRORING_ERROR_INVALID_OPERATION;
        } else {
                scmirroring_debug("Sent message [%s] successfully", _cmd);
@@ -504,6 +506,7 @@ int scmirroring_src_connect(scmirroring_src_h scmirroring)
        int sock = -1;
        GIOChannel *channel = NULL;
        struct timeval tv_timeout = { TIMEOUT_SEC, 0 };
+       char buf[255] = {0, };
 
        scmirroring_src_s *_scmirroring = (scmirroring_src_s *)scmirroring;
 
@@ -515,19 +518,22 @@ int scmirroring_src_connect(scmirroring_src_h scmirroring)
 
        /*Create TCP Socket*/
        if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
-               scmirroring_error("socket failed: %s", strerror(errno));
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("socket failed: %s", buf);
                return SCMIRRORING_ERROR_INVALID_OPERATION;
        }
 
        if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
-               scmirroring_error("setsockopt failed: %s", strerror(errno));
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("setsockopt failed: %s", buf);
                close(sock);
                return SCMIRRORING_ERROR_INVALID_OPERATION;
        }
 
        channel = g_io_channel_unix_new(sock);
        if (channel == NULL) {
-               scmirroring_error("g_io_channel_unix_new failed: %s", strerror(errno));
+               strerror_r(errno, buf, sizeof(buf));
+               scmirroring_error("g_io_channel_unix_new failed: %s", buf);
        }
 
        g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
@@ -564,7 +570,8 @@ try:
                                goto try;
                        }
 
-                       scmirroring_error("Connect error : %s", strerror(errno));
+                       strerror_r(errno, buf, sizeof(buf));
+                       scmirroring_error("Connect error : %s", buf);
                        close(_scmirroring->sock);
                        _scmirroring->sock = -1;
                        return SCMIRRORING_ERROR_INVALID_OPERATION;