From fb319d317ab3943d10cd3b8eff8c7f14f4aae044 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Wed, 1 Jul 2026 17:59:32 -0500 Subject: [PATCH 1/4] fix: Fix -Wrestrict --- src/ps2link.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ps2link.c b/src/ps2link.c index 563aa67..9f3fa3f 100644 --- a/src/ps2link.c +++ b/src/ps2link.c @@ -47,13 +47,13 @@ console_socket = network_listen(0x4712, SOCK_DGRAM); // Create the console thread. - if (console_socket > 0) { pthread_create(&console_thread_id, NULL, ps2link_thread_console, (void *)&console_thread_id); } + if (console_socket > 0) { pthread_create(&console_thread_id, NULL, ps2link_thread_console, NULL); } // Connect to the request port. request_socket = network_connect(hostname, 0x4711, SOCK_STREAM); // Create the request thread. - if (request_socket > 0) { pthread_create(&request_thread_id, NULL, ps2link_thread_request, (void *)&request_thread_id); } + if (request_socket > 0) { pthread_create(&request_thread_id, NULL, ps2link_thread_request, NULL); } // Connect to the command port. command_socket = network_connect(hostname, 0x4712, SOCK_DGRAM); @@ -813,11 +813,12 @@ int ps2link_response_getstat(int result, unsigned int mode, unsigned int attr, u // PS2LINK THREAD FUNCTIONS // ////////////////////////////// - void *ps2link_thread_console(void *thread_id) { + void *ps2link_thread_console(void *userdata) { char buffer[1024]; + (void)userdata; // If the socket isn't open, this thread isn't needed. - if (console_socket < 0) { pthread_exit(thread_id); } + if (console_socket < 0) { return NULL; } // Loop forever... for (;;) { @@ -844,11 +845,12 @@ int ps2link_response_getstat(int result, unsigned int mode, unsigned int attr, u } - void *ps2link_thread_request(void *thread_id) { + void *ps2link_thread_request(void *userdata) { struct { unsigned int number; unsigned short length; char buffer[512]; } PACKED packet; + (void)userdata; // If the socket isn't open, this thread isn't needed. - if (request_socket < 0) { pthread_exit(thread_id); } + if (request_socket < 0) { return NULL; } // Loop forever... for (;;) { From 123cf41c22ae3e69b6aa1d0ce04b8a4bd6e300de Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Wed, 1 Jul 2026 18:07:10 -0500 Subject: [PATCH 2/4] refactor: Avoid strncpy It has major flaws: * Will zero initialize extra memory after NULL terminator * Will not NULL terminate if written bytes is equal to buffer size --- doc/ps2link-protocol.txt | 6 +++--- doc/ps2netfs-protocol.txt | 22 +++++++++++----------- src/fsclient.c | 4 ++-- src/ps2client.c | 4 ++-- src/ps2link.c | 8 ++++---- src/ps2netfs.c | 20 ++++++++++---------- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/doc/ps2link-protocol.txt b/doc/ps2link-protocol.txt index 7dc4443..1385cfd 100644 --- a/doc/ps2link-protocol.txt +++ b/doc/ps2link-protocol.txt @@ -113,7 +113,7 @@ command.length = htons(sizeof(command)); command.offset = htonl(offset); command.size = htonl(size); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } ------------------------------ 0xBABE0208 (startvu command) @@ -168,7 +168,7 @@ command.number = htonl(0xBABE020A); command.length = htons(sizeof(command)); command.type = htonl(type); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } ----------------------------- 0xBABE020B (gsexec command) @@ -185,7 +185,7 @@ command.number = htonl(0xBABE020B); command.length = htons(sizeof(command)); command.size = htonl(size); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } -------------------------------------- PS2LINK REQUEST AND RESPONSE PACKETS diff --git a/doc/ps2netfs-protocol.txt b/doc/ps2netfs-protocol.txt index 66491f7..d8c1553 100644 --- a/doc/ps2netfs-protocol.txt +++ b/doc/ps2netfs-protocol.txt @@ -35,7 +35,7 @@ request.number = htonl(0xBEEF8011); request.length = htons(sizeof(request)); request.flags = htonl(mode); - if (pathname) { strncpy(request.pathname, pathname, 256); } + if (pathname) { snprintf(request.pathname, sizeof(request.pathname), "%s", pathname); } ----------------------------- 0xBEEF8021 (close request) @@ -131,7 +131,7 @@ request.number = htonl(0xBEEF8071); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (pathname) { strncpy(request.pathname, pathname, 256); } + if (pathname) { snprintf(request.pathname, sizeof(request.pathname), "%s", pathname); } ----------------------------- 0xBEEF8081 (mkdir request) @@ -148,7 +148,7 @@ request.number = htonl(0xBEEF8081); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (pathname) { strncpy(request.pathname, pathname, 256); } + if (pathname) { snprintf(request.pathname, sizeof(request.pathname), "%s", pathname); } ----------------------------- 0xBEEF8091 (rmdir request) @@ -165,7 +165,7 @@ request.number = htonl(0xBEEF8091); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (pathname) { strncpy(request.pathname, pathname, 256); } + if (pathname) { snprintf(request.pathname, sizeof(request.pathname), "%s", pathname); } ------------------------------ 0xBEEF80A1 (dopen request) @@ -182,7 +182,7 @@ request.number = htonl(0xBEEF80A1); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (pathname) { strncpy(request.pathname, pathname, 256); } + if (pathname) { snprintf(request.pathname, sizeof(request.pathname), "%s", pathname); } ------------------------------ 0xBEEF80B1 (dclose request) @@ -245,7 +245,7 @@ request.number = htonl(0xBEEF8131); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (device) { strncpy(request.device, device, 256); } + if (device) { snprintf(request.device, sizeof(request.device), "%s", device); } ----------------------------- 0xBEEF8141 (mount request) @@ -268,9 +268,9 @@ request.length = htons(sizeof(request)); request.flags = htonl(flags); request.argc = htonl(argc); - if (device) { strncpy(request.device, device, 256); } - if (fsname) { strncpy(request.fsname, fsname, 256); } - if (argv) { strncpy(request.argv, argv, 256); } + if (device) { snprintf(request.device, sizeof(request.device), "%s", device); } + if (fsname) { snprintf(request.fsname, sizeof(request.fsname), "%s", fsname); } + if (argv) { snprintf(request.argv, sizeof(request.argv), "%s", argv); } ------------------------------ 0xBEEF8151 (umount request) @@ -287,7 +287,7 @@ request.number = htonl(0xBEEF8151); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (device) { strncpy(request.device, device, 256); } + if (device) { snprintf(request.device, sizeof(request.device), "%s", device); } ------------------------------- 0xBEEF8F21 (devlist request) @@ -304,4 +304,4 @@ request.number = htonl(0xBEEF8F21); request.length = htons(sizeof(request)); request.flags = htonl(flags); - if (pathname) { strncpy(request.pathname, pathname, 256); } + if (pathname) { snprintf(request.pathname, sizeof(request.pathname), "%s", pathname); } diff --git a/src/fsclient.c b/src/fsclient.c index d39c4a7..692eee7 100644 --- a/src/fsclient.c +++ b/src/fsclient.c @@ -24,7 +24,7 @@ for (loop0=0; env[loop0]; loop0++) { // A hostname has been specified... - if (strncmp(env[loop0], "PS2HOSTNAME", 11) == 0) { strncpy(hostname, &env[loop0][12], sizeof(hostname)); } + if (strncmp(env[loop0], "PS2HOSTNAME", 11) == 0) { snprintf(hostname, sizeof(hostname), "%s", &env[loop0][12]); } } @@ -41,7 +41,7 @@ if (argc == loop0) { printf("Error: No hostname was supplied the '-h' option.\n"); print_usage(); return -1; } // Set the hostname to the supplied value. - strncpy(hostname, argv[loop0], sizeof(hostname)); + snprintf(hostname, sizeof(hostname), "%s", argv[loop0]); } diff --git a/src/ps2client.c b/src/ps2client.c index 7631795..42e18b0 100644 --- a/src/ps2client.c +++ b/src/ps2client.c @@ -22,7 +22,7 @@ for (loop0=0; env[loop0]; loop0++) { // A hostname has been specified... - if (strncmp(env[loop0], "PS2HOSTNAME", 11) == 0) { strncpy(hostname, &env[loop0][12], sizeof(hostname)); } + if (strncmp(env[loop0], "PS2HOSTNAME", 11) == 0) { snprintf(hostname, sizeof(hostname), "%s", &env[loop0][12]); } } @@ -39,7 +39,7 @@ if (argc == loop0) { printf("Error: No hostname was supplied the '-h' option.\n"); print_usage(); return -1; } // Set the hostname to the supplied value. - strncpy(hostname, argv[loop0], sizeof(hostname)); + snprintf(hostname, sizeof(hostname), "%s", argv[loop0]); } diff --git a/src/ps2link.c b/src/ps2link.c index 9f3fa3f..f914b87 100644 --- a/src/ps2link.c +++ b/src/ps2link.c @@ -193,7 +193,7 @@ command.length = htons(sizeof(command)); command.offset = htonl(offset); command.size = htonl(size); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. return network_send(command_socket, &command, sizeof(command)); @@ -233,7 +233,7 @@ command.number = htonl(PS2LINK_COMMAND_DUMPREG); command.length = htons(sizeof(command)); command.type = htonl(type); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. return network_send(command_socket, &command, sizeof(command)); @@ -247,7 +247,7 @@ command.number = htonl(PS2LINK_COMMAND_GSEXEC); command.length = htons(sizeof(command)); command.size = htonl(size); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. return network_send(command_socket, &command, sizeof(command)); @@ -262,7 +262,7 @@ command.length = htons(sizeof(command)); command.offset = htonl(offset); command.size = htonl(size); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. return network_send(command_socket, &command, sizeof(command)); diff --git a/src/ps2netfs.c b/src/ps2netfs.c index d654aa4..ac97d37 100644 --- a/src/ps2netfs.c +++ b/src/ps2netfs.c @@ -159,7 +159,7 @@ command.number = htonl(PS2NETFS_COMMAND_DELETE); command.length = htons(sizeof(command)); command.flags = htonl(flags); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -180,7 +180,7 @@ command.number = htonl(PS2NETFS_COMMAND_MKDIR); command.length = htons(sizeof(command)); command.flags = htonl(flags); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -201,7 +201,7 @@ command.number = htonl(PS2NETFS_COMMAND_RMDIR); command.length = htons(sizeof(command)); command.flags = htonl(flags); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -222,7 +222,7 @@ command.number = htonl(PS2NETFS_COMMAND_DOPEN); command.length = htons(sizeof(command)); command.flags = htonl(flags); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -296,7 +296,7 @@ command.number = htonl(PS2NETFS_COMMAND_SYNC); command.length = htons(sizeof(command)); command.flags = htonl(flags); - if (device) { strncpy(command.device, device, 256); } + if (device) { snprintf(command.device, sizeof(command.device), "%s", device); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -318,9 +318,9 @@ command.length = htons(sizeof(command)); command.flags = htonl(flags); command.argc = htonl(argc); - if (device) { strncpy(command.device, device, 256); } - if (fsname) { strncpy(command.fsname, fsname, 256); } - if (argv) { strncpy(command.argv, argv, 256); } + if (device) { snprintf(command.device, sizeof(command.device), "%s", device); } + if (fsname) { snprintf(command.fsname, sizeof(command.fsname), "%s", fsname); } + if (argv) { snprintf(command.argv, sizeof(command.argv), "%s", argv); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -340,7 +340,7 @@ // Build the command packet. command.number = htonl(PS2NETFS_COMMAND_UMOUNT); command.length = htons(sizeof(command)); - if (device) { strncpy(command.device, device, 256); } + if (device) { snprintf(command.device, sizeof(command.device), "%s", device); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } @@ -375,7 +375,7 @@ command.number = htonl(PS2NETFS_COMMAND_DEVLIST); command.length = htons(sizeof(command)); command.flags = htonl(flags); - if (pathname) { strncpy(command.pathname, pathname, 256); } + if (pathname) { snprintf(command.pathname, sizeof(command.pathname), "%s", pathname); } // Send the command packet. if (network_send(ps2netfs_socket, &command, sizeof(command)) < 0) { return -1; } From 5514e6207e6ece37d1d6a55bd7bc5f8898b9fa4c Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Wed, 1 Jul 2026 18:08:16 -0500 Subject: [PATCH 3/4] fix: Fix instance of -Wunused-parameter --- src/ps2netfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ps2netfs.c b/src/ps2netfs.c index ac97d37..30fba42 100644 --- a/src/ps2netfs.c +++ b/src/ps2netfs.c @@ -337,6 +337,7 @@ struct { unsigned int number; unsigned short length; int flags; char device[256]; } PACKED command; struct { unsigned int number; unsigned short length; int result; } PACKED response; + (void)flags; // Build the command packet. command.number = htonl(PS2NETFS_COMMAND_UMOUNT); command.length = htons(sizeof(command)); From 5a32a6f188f800c01ff66c096374f81dee1a7f3a Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Wed, 1 Jul 2026 18:09:04 -0500 Subject: [PATCH 4/4] fix: Fix instance of -Wsign-compare --- src/utility.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility.c b/src/utility.c index 22a65bc..76eccdd 100644 --- a/src/utility.c +++ b/src/utility.c @@ -33,7 +33,7 @@ } - int fix_pathname(char *pathname) { int loop0 = 0; + int fix_pathname(char *pathname) { unsigned int loop0 = 0; // If empty, set a pathname default. if (pathname[0] == 0) { strcpy(pathname, "."); }