aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-10-01 09:12:33 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-10-01 09:12:33 +0000
commite319439395a6b77f901afe57094259d72b1ada75 (patch)
tree00a1c655079d5b30e65462553ce9d3747c680980
parentf011b5da618d5569cbbd246f2bd82e4aaf24832c (diff)
downloadChibiOS-e319439395a6b77f901afe57094259d72b1ada75.tar.gz
ChibiOS-e319439395a6b77f901afe57094259d72b1ada75.tar.bz2
ChibiOS-e319439395a6b77f901afe57094259d72b1ada75.zip
Fixed bug #645.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8339 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.c102
-rw-r--r--demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.h16
-rw-r--r--os/various/syscalls.c2
-rw-r--r--readme.txt2
4 files changed, 105 insertions, 17 deletions
diff --git a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.c b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.c
index 1907fc633..c0e717b0f 100644
--- a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.c
+++ b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.c
@@ -26,6 +26,8 @@
* @{
*/
+#include <ctype.h>
+
#include "ch.h"
#include "lwip/opt.h"
@@ -36,6 +38,81 @@
#if LWIP_NETCONN
+static char url_buffer[WEB_MAX_PATH_SIZE];
+
+#define HEXTOI(x) (isdigit(x) ? (x) - '0' : (x) - 'a' + 10)
+
+/**
+ * @brief Decodes an URL sting.
+ * @note The string is terminated by a zero or a separator.
+ *
+ * @param[in] url encoded URL string
+ * @param[out] buf buffer for the processed string
+ * @param[in] max max number of chars to copy into the buffer
+ * @return The conversion status.
+ * @retval false string converted.
+ * @retval true the string was not valid or the buffer overflowed
+ *
+ * @notapi
+ */
+static bool decode_url(const char *url, char *buf, size_t max) {
+
+ while (true) {
+ int h, l;
+ unsigned c = *url++;
+
+ switch (c) {
+ case 0:
+ case '\r':
+ case '\n':
+ case '\t':
+ case ' ':
+ case '?':
+ *buf = 0;
+ return false;
+ case '.':
+ if (max <= 1)
+ return true;
+
+ h = *(url + 1);
+ if (h == '.')
+ return true;
+
+ break;
+ case '%':
+ if (max <= 1)
+ return true;
+
+ h = tolower((int)*url++);
+ if (h == 0)
+ return true;
+ if (!isxdigit(h))
+ return true;
+
+ l = tolower((int)*url++);
+ if (l == 0)
+ return true;
+ if (!isxdigit(l))
+ return true;
+
+ c = (char)((HEXTOI(h) << 4) | HEXTOI(l));
+ break;
+ default:
+ if (max <= 1)
+ return true;
+
+ if (!isalnum(c) && (c != '_') && (c != '-') && (c != '+') &&
+ (c != '/'))
+ return true;
+
+ break;
+ }
+
+ *buf++ = c;
+ max--;
+ }
+}
+
static const char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
static const char http_index_html[] = "<html><head><title>Congrats!</title></head><body><h1>Welcome to our lwIP HTTP server!</h1><p>This is a small test page.</body></html>";
@@ -46,20 +123,25 @@ static void http_server_serve(struct netconn *conn) {
err_t err;
/* Read the data from the port, blocking if nothing yet there.
- We assume the request (the part we care about) is in one netbuf */
+ We assume the request (the part we care about) is in one netbuf.*/
err = netconn_recv(conn, &inbuf);
if (err == ERR_OK) {
netbuf_data(inbuf, (void **)&buf, &buflen);
/* Is this an HTTP GET command? (only check the first 5 chars, since
- there are other formats for GET, and we're keeping it very simple )*/
- if (buflen>=5 &&
- buf[0]=='G' &&
- buf[1]=='E' &&
- buf[2]=='T' &&
- buf[3]==' ' &&
- buf[4]=='/' ) {
+ there are other formats for GET, and we're keeping it very simple ).*/
+ if (buflen >= 5 &&
+ buf[0] == 'G' &&
+ buf[1] == 'E' &&
+ buf[2] == 'T' &&
+ buf[3] == ' ' &&
+ buf[4] == '/') {
+
+ if (decode_url(buf + 4, url_buffer, WEB_MAX_PATH_SIZE)) {
+ /* Invalid URL handling.*/
+ return;
+ }
/* Send the HTML header
* subtract 1 from the size, since we dont send the \0 in the string
@@ -80,12 +162,12 @@ static void http_server_serve(struct netconn *conn) {
}
/**
- * Stack area for the http thread.
+ * @brief Stack area for the http thread.
*/
THD_WORKING_AREA(wa_http_server, WEB_THREAD_STACK_SIZE);
/**
- * HTTP server thread.
+ * @brief HTTP server thread.
*/
THD_FUNCTION(http_server, p) {
struct netconn *conn, *newconn;
diff --git a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.h b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.h
index 902bf9be4..946576b8d 100644
--- a/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.h
+++ b/demos/STM32/RT-STM32F746G-DISCOVERY-LWIP-FATFS-USB/web/web.h
@@ -24,16 +24,20 @@
#ifndef _WEB_H_
#define _WEB_H_
-#ifndef WEB_THREAD_STACK_SIZE
-#define WEB_THREAD_STACK_SIZE 1024
+#if !defined(WEB_THREAD_STACK_SIZE)
+#define WEB_THREAD_STACK_SIZE 1024
#endif
-#ifndef WEB_THREAD_PORT
-#define WEB_THREAD_PORT 80
+#if !defined(WEB_THREAD_PORT)
+#define WEB_THREAD_PORT 80
#endif
-#ifndef WEB_THREAD_PRIORITY
-#define WEB_THREAD_PRIORITY (LOWPRIO + 2)
+#if !defined(WEB_THREAD_PRIORITY)
+#define WEB_THREAD_PRIORITY (LOWPRIO + 2)
+#endif
+
+#if !defined(WEB_MAX_PATH_SIZE)
+#define WEB_MAX_PATH_SIZE 128
#endif
extern THD_WORKING_AREA(wa_http_server, WEB_THREAD_STACK_SIZE);
diff --git a/os/various/syscalls.c b/os/various/syscalls.c
index ad6031d87..7a4d04845 100644
--- a/os/various/syscalls.c
+++ b/os/various/syscalls.c
@@ -132,7 +132,7 @@ caddr_t _sbrk_r(struct _reent *r, int incr)
#if CH_CFG_USE_MEMCORE
void *p;
- chDbgCheck(incr > 0);
+ chDbgCheck(incr >= 0);
p = chCoreAlloc((size_t)incr);
if (p == NULL) {
diff --git a/readme.txt b/readme.txt
index 29c3d62d2..534453ed4 100644
--- a/readme.txt
+++ b/readme.txt
@@ -116,6 +116,8 @@
- HAL: Introduced support for TIM21 and TIM22 in STM32 ST driver.
- HAL: Updated STM32F0xx headers to STM32CubeF0 version 1.3.0. Added support
for STM32F030xC, STM32F070x6, STM32F070xB devices.
+- VAR: Fixed _sbrk_r with incr == 0 should be valid (bug #645)(backported to
+ 3.0.3 and 2.6.10).
- RT: Fixed issues in CMSIS RTOS interface (bug #644)(backported to 3.0.3).
- HAL: Fixed RT dependency in STM32 SDCv1 driver (bug #643)(backported
to 3.0.2).