const char *hostname = "irc.patchysicp.xyz";
int processPacket(struct client_data *client) {
char *source = NULL;
+ (void)source;
char *command = NULL;
char *args[16] = {0};
int argc = 0;
{
char *p = client->buf;
{ // remove \r
- char *end = strchr(p, '\n');
- if (!end) {
+ char *end = memchr(p, '\n', client->bufLen);
+ if (end > p && end[-1] == '\r')
+ *--end = '\n';
+ if (memchr(p, '\0', end-p)) {
printf("Client %"PRISocket" sent a NULL\n", client->FD);
fflush(stdout);
killConnection(client, false);
return 1; // null detected
}
- if (end > p && end[-1] == '\r')
- end[-1] = '\n';
- if (strchr(p, '\r')) {
+ if (memchr(p, '\r', end-p)) {
printf("Client %"PRISocket" sent an extra CR\n", client->FD);
fflush(stdout);
killConnection(client, false);
size_t i;
// TODO: perform basic sanitization
- // Remove newline
- for(i=0;i<size;i++){
- // Space
- if(nickname[i] == ' ') {
- nickname[i] = 0;
- break;
- }
- }
+ char *bruh = strchr(nickname, ' '); // FIXME: we should reject those tbh
+ if (*bruh)
+ *bruh = 0;
// Start GitHub Copilot
// Check if the nickname is already taken
void recvProc(struct client_data *cl) {
ssize_t bytesRead;
char *x;
- char tmp;
int packetReturn;
while(1){
// I hate you
while(1){
x = memchr(cl->buf, '\n', cl->bufLen);
if(!x) break;
- tmp = *(x+1);
- *(x+1) = '\0';
packetReturn = processPacket(cl);
// Client QUIT
if(packetReturn == 1) {
return;
}
- *(x+1) = tmp;
memmove(cl->buf, x+1, cl->buf + cl->bufLen-(x+1));
cl->bufLen -= x+1 - cl->buf;
}