Skip to content
Snippets Groups Projects
Commit 7384d380 authored by fptk's avatar fptk
Browse files

working form on arty

parent a9188082
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@
#include "queue.h"
#include "tcp_cb.h"
#include "message_handling.h"
// ----------------------------------------------------------------------------
......@@ -59,16 +60,7 @@ time_t time(time_t *timer) {
// ----------------------------------------------------------------------------
#define printf2(format, args...) { /* Multi-part printf() */\
char *str = malloc(64); \
if (str != NULL){ \
const int len = snprintf(str, 64, format, ## args); \
for (int i=0; i<(len/16)+1; i++){ \
while(!MZONE_SEND(2, (str+16*i))) MZONE_YIELD(); \
} \
free(str); \
} \
} \
static struct netif netif;
static struct queue *rx_queue;
......@@ -145,23 +137,7 @@ __attribute__((interrupt())) void plic_handler(void) { // machine external inter
}
static int msg_handler(const int zone, const char *msg){
// consumed messages are processed locally and not forwarded to the broker
int consumed = 0;
if (strcmp("ping", msg)==0){
MZONE_SEND(zone, "pong");
consumed = 1;
} else if (strcmp("broker hello", msg)==0){
MZONE_SEND(zone, "online");
}
return consumed;
}
//The flags in lwip/opts.h need to be 1, otherwise these CBs won't be called
static void netif_link_callback(struct netif *netif) {
......
#include "message_handling.h"
static int msg_handler(const int zone, const char *msg) {
// consumed messages are processed locally and not forwarded to the broker
int consumed = 0;
if (strcmp("ping", msg)==0){
MZONE_SEND(zone, "pong");
consumed = 1;
} else if (strcmp("broker hello", msg)==0){
MZONE_SEND(zone, "online");
}
return consumed;
}
#ifndef ZONE1_MESSAGE_HANDLING_H_
#define ZONE1_MESSAGE_HANDLING_H_
//taken from the multizone-iot-sdk source
#include "multizone.h"
#define printf2(format, args...) { /* Multi-part printf() */\
char *str = malloc(64); \
if (str != NULL){ \
const int len = snprintf(str, 64, format, ## args); \
for (int i=0; i<(len/16)+1; i++){ \
while(!MZONE_SEND(2, (str+16*i))) MZONE_YIELD(); \
} \
free(str); \
} \
} \
static int msg_handler(const int zone, const char *msg);
#endif /* ZONE1_MESSAGE_HANDLING_H_ */
/*
* server_utility.h
*
* Created on: Feb 19, 2021
* Author: riscv
*/
#ifndef SERVER_UTILITY_H_
#define SERVER_UTILITY_H_
#include "http_helpers.h"
#include "webserver.h"
#include "message_handling.h"
#define INDEX_PAGE \
"<!DOCTYPE html>\n"\
......@@ -44,15 +38,14 @@ int is_target(char *test) {
return strncmp(test, target, strlen(target)) == 0;
}
/*
* char message[128];
printf("Framepointer: 0x%x\n", *(uint32_t *)&message[140]);
printf("Rücksprungadresse: 0x%x\n", *(uint32_t *)&message[140] - 204);
*/
char *attack_me(char *data, uint32_t data_len) {
// nobody could possibly enter a name longer than 20 characters, so this buffer
// is definitely large enough
char message[128];
//for debugging purpose
printf2("Framepointer: 0x%x\n", *(uint32_t *)&message[140]);
printf2("Rücksprungadresse: 0x%x\n", *(uint32_t *)&message[140] - 204);
memset(message, 'B', sizeof(message));
memcpy(message, "Hallo, ", 7);
......@@ -80,7 +73,7 @@ char *server_request_handler(char *location, enum request_type type, char *data,
// nobody could possibly enter a name longer than 20 characters, so this buffer
// is definitely large enough
char *return_string;
return_string = attack_me(data, name_len);
return_string = attack_me(&data[5], name_len);
char* response = http_prepare_response(return_string, strlen(return_string), 200, out_len);
free(return_string);
......
......@@ -8,11 +8,11 @@
#include "tcp_cb.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//for enums
#include "tcp_cb.h"
#include "server_utility.h"
......@@ -94,7 +94,7 @@ static err_t tcp_cb_parse_http(struct altcp_pcb *package_control_block, struct t
if(free_result) {
free(response);
}
tcp_state->state = TCP_CLOSING;
return error_rv;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment