소스 검색

fixing potential strncat buffer overrun

* diu_kiosk uses /home/bus instead of $HOME
clementinecomputing 6 년 전
부모
커밋
fa4fa4086d
2개의 변경된 파일56개의 추가작업 그리고 21개의 파일을 삭제
  1. 22 2
      busunit/DIUv2/diu_kiosk
  2. 34 19
      busunit/DIUv2/diu_main.c

+ 22 - 2
busunit/DIUv2/diu_kiosk

@@ -1,4 +1,24 @@
 #!/bin/bash
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+#
+# This file is part of PopuFare.
+#
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+export BASEDIR=/home/pi
 
 export DISPLAY=:0
 
@@ -20,8 +40,8 @@ unclutter -idle 0.05 -root &
 # clear out warning bar on chromium
 #
 tmpfn=`mktemp`
-jq '.profile.exited_cleanly = true' $HOME/.config/chromium/Preferences | jq '.profile.exit_type = "Normal"' > $tmpfn
-mv $tmpfn $HOME/.config/chromium/Preferences
+jq '.profile.exited_cleanly = true' $BASEDIR/.config/chromium/Preferences | jq '.profile.exit_type = "Normal"' > $tmpfn
+mv $tmpfn $BASEDIR/.config/chromium/Preferences
 
 # start chromium in kiosk mode
 #

+ 34 - 19
busunit/DIUv2/diu_main.c

@@ -44,11 +44,8 @@
 
 #define _SLEN LINE_BUFFER_SIZE
 
-/*
-#include "fbutil.h"
-#include "expat-2.0.1/lib/expat.h"
-#include "menu.h"
-*/
+static const char *s_http_port = "60535";
+static struct mg_serve_http_opts s_http_server_opts;
 
 struct mg_mgr g_mgr;
 
@@ -65,6 +62,26 @@ time_t mkgmtime(struct tm *tm);
 int   token_diag_serial = 0;
 char   token_diag_string[LINE_BUFFER_SIZE] = {0};
 
+
+// return total bytes in dst
+//
+static size_t _strnncat(char *dst, char *src, size_t n) {
+  size_t dst_n, src_n, N, i;
+
+  dst_n = strlen(dst);
+  src_n = strlen(src);
+  N = n-1;
+  if (dst_n < N) { N -= dst_n; }
+
+  for (i=0; (i<N) && (i<src_n); i++) {
+    dst[dst_n + i] = src[i];
+  }
+
+  dst[dst_n+i] = '\0';
+
+  return dst_n + i;
+}
+
 //unsigned char menu_checksum[MD5_DIGEST_LENGTH];
 
 time_t paddle_req_timeout = 0;
@@ -634,9 +651,7 @@ static inline int can_report_diu_error()
 
 //-------- web server functions ----
 
-static const char *s_http_port = "60535";
-static struct mg_serve_http_opts s_http_server_opts;
-
+/*
 static void send_ws_heartbeat(struct mg_connection *nc) {
   int n;
   char buf[_SLEN];
@@ -653,6 +668,7 @@ static void send_ws_heartbeat(struct mg_connection *nc) {
   }
 
 }
+*/
 
 static void process_ws_message(struct websocket_message *ws_msg) {
   int i;
@@ -695,10 +711,11 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
                           pkgs[i].pkgname, pkgs[i].pkgver,
                           pkgtime.tm_mon + 1, pkgtime.tm_mday, pkgtime.tm_year + 1900,
                           pkgtime.tm_hour, pkgtime.tm_min, pkgtime.tm_sec);
-    //if (npkgnet>0) { strncat(pkgnetline, "|", _SLEN); }
-    strncat(pkgnetline, "|", _SLEN);
-    strncat(pkgnetline, _str, _SLEN);
+
+		_strnncat(pkgnetline, "|", _SLEN);
+    _strnncat(pkgnetline, _str, _SLEN);
     npkgnet++;
+
   }
 
   fp = fopen("/tmp/net_ids", "rb");
@@ -706,8 +723,8 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
     i=0;
     while (fgets(_str, _SLEN, fp)) {
       strip_crlf(_str);
-      strncat(pkgnetline, "|", _SLEN);
-      strncat(pkgnetline, _str, _SLEN);
+      _strnncat(pkgnetline, "|", _SLEN);
+      _strnncat(pkgnetline, _str, _SLEN);
       npkgnet++;
     }
     fclose(fp);
@@ -747,9 +764,6 @@ static void ui_handle_status_input(struct mg_connection *nc, struct http_message
 
       pkgnetline);
 
-  //DEBUG
-  printf("%s\n", buf);
-
   mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
       (unsigned long)strlen(buf), buf);
 }
@@ -892,8 +906,6 @@ static void ui_handle_driver_login(struct mg_connection *nc, struct http_message
 static void api_handle_req(struct mg_connection *nc, struct http_message *hm) {
   int ret;
   char s_action[_SLEN];
-  char _default_msg[_SLEN] = "";
-  struct mg_str hdr;
 
   ret = mg_get_http_var(&(hm->body), "action", s_action, _SLEN);
 
@@ -1064,7 +1076,7 @@ int main(int argc, char **argv) {
   }
 
   mg_set_protocol_http_websocket(nc);
-  s_http_server_opts.document_root = "html";
+  s_http_server_opts.document_root = CONFIG_FILE_PATH "/html";
   s_http_server_opts.enable_directory_listing = "no";
 
 
@@ -1504,6 +1516,9 @@ int main(int argc, char **argv) {
           else {
             message_callback_return msg_status;
             msg_status = process_message(&incoming_msg);
+            if (msg_status) {
+              //pass
+            }
           }
 
         }