Skip to content

Commit

Permalink
address a couple of undefined behavior that caused issues with -O2, a…
Browse files Browse the repository at this point in the history
…nd some cosmetics
  • Loading branch information
john-tornblom committed May 22, 2024
1 parent 7a38b09 commit b7b35cf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/asset.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with this program; see the file COPYING. If not, see

#include <microhttpd.h>

#include "asset.h"
#include "fs.h"
#include "websrv.h"

Expand Down Expand Up @@ -61,11 +62,11 @@ asset_register(const char* path, void* data, size_t size) {

enum MHD_Result
asset_request(struct MHD_Connection *conn, const char* url) {
int status = MHD_HTTP_NOT_FOUND;
unsigned int status = MHD_HTTP_NOT_FOUND;
enum MHD_Result ret = MHD_NO;
size_t size = strlen(PAGE_404);
struct MHD_Response *resp;
void* data = PAGE_404;
int ret = MHD_NO;

for(asset_t* a=g_asset_head; a!=0; a=a->next) {
if(!strcmp(url, a->path)) {
Expand Down
6 changes: 3 additions & 3 deletions src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ dir_close(void *cls) {
**/
static enum MHD_Result
file_request(struct MHD_Connection *conn, const char* path) {
enum MHD_Result ret = MHD_NO;
struct MHD_Response *resp;
int ret = MHD_NO;
struct stat st;
FILE *file = 0;

Expand Down Expand Up @@ -253,10 +253,10 @@ file_request(struct MHD_Connection *conn, const char* path) {
static enum MHD_Result
dir_request(struct MHD_Connection *conn, const char* path) {
MHD_ContentReaderCallback dir_read_cb;
enum MHD_Result ret = MHD_NO;
size_t len = strlen(path);
struct MHD_Response *resp;
char url[PATH_MAX];
int ret = MHD_NO;
dir_read_sm_t sm;
const char* mime;
const char* fmt;
Expand Down Expand Up @@ -313,9 +313,9 @@ dir_request(struct MHD_Connection *conn, const char* path) {

enum MHD_Result
fs_request(struct MHD_Connection *conn, const char* url) {
enum MHD_Result ret = MHD_NO;
struct MHD_Response *resp;
const char* path = url+3;
int ret = MHD_NO;
struct stat st;

if(!strlen(path)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ along with this program; see the file COPYING. If not, see


int
main() {
main(int argc, char** argv) {
const uint16_t port = 8080;

printf("Web server was compiled at %s %s\n", __DATE__, __TIME__);
Expand Down
9 changes: 5 additions & 4 deletions src/ps5/hbldr.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ along with this program; see the file COPYING. If not, see
#include <ps5/mdbg.h>

#include "elfldr.h"
#include "hbldr.h"
#include "pt.h"
#include "sys.h"
#include "websrv.h"
Expand All @@ -43,8 +44,8 @@ along with this program; see the file COPYING. If not, see
#define PSNOW_EBOOT "/system_ex/app/NPXS40106/eboot.bin"
#define FAKE_PATH "/system_ex/app/FAKE00000"

#define IOVEC_ENTRY(x) {x ? x : 0, \
x ? strlen(x)+1 : 0}
#define IOVEC_ENTRY(x) {x != 0 ? x : 0, \
x != 0 ? strlen(x)+1 : 0}
#define IOVEC_SIZE(x) (sizeof(x) / sizeof(struct iovec))


Expand Down Expand Up @@ -83,7 +84,7 @@ int sceSystemServiceLaunchApp(const char* title_id, char** argv,
app_launch_ctx_t* ctx);


int
static int
remount_system_ex(void) {
struct iovec iov[] = {
IOVEC_ENTRY("from"), IOVEC_ENTRY("/dev/ssd0.system_ex"),
Expand Down Expand Up @@ -336,7 +337,7 @@ bigapp_launch(uint32_t user_id, char** argv) {
/**
* Set the name of a process.
**/
int
static int
bigapp_set_procname(pid_t pid, const char* name) {
intptr_t buf;

Expand Down
32 changes: 16 additions & 16 deletions src/ps5/pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pt_setregs(pid_t pid, const struct reg *r) {
}


long
static long
pt_call(pid_t pid, intptr_t addr, ...) {
struct reg jmp_reg;
struct reg bak_reg;
Expand All @@ -165,12 +165,12 @@ pt_call(pid_t pid, intptr_t addr, ...) {
jmp_reg.r_rip = addr;

va_start(ap, addr);
jmp_reg.r_rdi = va_arg(ap, uint64_t);
jmp_reg.r_rsi = va_arg(ap, uint64_t);
jmp_reg.r_rdx = va_arg(ap, uint64_t);
jmp_reg.r_rcx = va_arg(ap, uint64_t);
jmp_reg.r_r8 = va_arg(ap, uint64_t);
jmp_reg.r_r9 = va_arg(ap, uint64_t);
jmp_reg.r_rdi = va_arg(ap, int64_t);
jmp_reg.r_rsi = va_arg(ap, int64_t);
jmp_reg.r_rdx = va_arg(ap, int64_t);
jmp_reg.r_rcx = va_arg(ap, int64_t);
jmp_reg.r_r8 = va_arg(ap, int64_t);
jmp_reg.r_r9 = va_arg(ap, int64_t);
va_end(ap);

if(pt_setregs(pid, &jmp_reg)) {
Expand Down Expand Up @@ -218,12 +218,12 @@ pt_syscall(pid_t pid, int sysno, ...) {
jmp_reg.r_rax = sysno;

va_start(ap, sysno);
jmp_reg.r_rdi = va_arg(ap, uint64_t);
jmp_reg.r_rsi = va_arg(ap, uint64_t);
jmp_reg.r_rdx = va_arg(ap, uint64_t);
jmp_reg.r_r10 = va_arg(ap, uint64_t);
jmp_reg.r_r8 = va_arg(ap, uint64_t);
jmp_reg.r_r9 = va_arg(ap, uint64_t);
jmp_reg.r_rdi = va_arg(ap, int64_t);
jmp_reg.r_rsi = va_arg(ap, int64_t);
jmp_reg.r_rdx = va_arg(ap, int64_t);
jmp_reg.r_r10 = va_arg(ap, int64_t);
jmp_reg.r_r8 = va_arg(ap, int64_t);
jmp_reg.r_r9 = va_arg(ap, int64_t);
va_end(ap);

if(pt_setregs(pid, &jmp_reg)) {
Expand Down Expand Up @@ -270,19 +270,19 @@ pt_mmap(pid_t pid, intptr_t addr, size_t len, int prot, int flags,

int
pt_msync(pid_t pid, intptr_t addr, size_t len, int flags) {
return pt_syscall(pid, SYS_msync, addr, len, flags);
return (int)pt_syscall(pid, SYS_msync, addr, len, flags);
}


int
pt_munmap(pid_t pid, intptr_t addr, size_t len) {
return pt_syscall(pid, SYS_munmap, addr, len);
return (int)pt_syscall(pid, SYS_munmap, addr, len);
}


int
pt_mprotect(pid_t pid, intptr_t addr, size_t len, int prot) {
return pt_syscall(pid, SYS_mprotect, addr, len, prot);
return (int)pt_syscall(pid, SYS_mprotect, addr, len, prot);
}


Expand Down
8 changes: 4 additions & 4 deletions src/websrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ websrv_split_args(char* args, char** argv, size_t size) {
size_t len = strlen(args);

memset(argv, 0, size*sizeof(char*));
for(int i=0, j=0; i<len && j<size; i++) {
for(size_t i=0, j=0; i<len && j<size; i++) {
if(args[i] == ' ') {
args[i] = 0;
continue;
Expand All @@ -70,11 +70,11 @@ websrv_split_args(char* args, char** argv, size_t size) {
**/
static enum MHD_Result
launch_request(struct MHD_Connection *conn, const char* url) {
enum MHD_Result ret = MHD_NO;
struct MHD_Response *resp;
const char* title_id;
unsigned int status;
const char *args;
int ret = MHD_NO;
int status;

title_id = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "titleId");
args = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "args");
Expand Down Expand Up @@ -102,11 +102,11 @@ launch_request(struct MHD_Connection *conn, const char* url) {
**/
static enum MHD_Result
hbldr_request(struct MHD_Connection *conn, const char* url) {
enum MHD_Result ret = MHD_NO;
struct MHD_Response *resp;
const char* path;
const char *args;
const char *pipe;
int ret = MHD_NO;
int fd;

path = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "path");
Expand Down

0 comments on commit b7b35cf

Please sign in to comment.