Skip to content
Snippets Groups Projects
Commit bc9d7fd6 authored by Christian Löpke's avatar Christian Löpke
Browse files

Added error handling in chardev_write if faulty memory is given.

parent efb31da7
Branches
No related tags found
No related merge requests found
Pipeline #
...@@ -192,10 +192,16 @@ device_write(struct file *filp, const char *buff, size_t len, loff_t * off) ...@@ -192,10 +192,16 @@ device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
} }
else { else {
int i; int i;
for(i = 0; i < len; i++) //Save the given string for(i = 0; i < len; i++) {//Save the given string
get_user(msg_username[i], buff + i); if(get_user(msg_username[i], buff + i) < 0) { //If returning error code
printk(KERN_WARNING "%s: You want to play a trick on me! This memory does not belong to you!\n",
DEVICE_NAME);
return -EFAULT; //Stop reading from userspace.
}
//msg_username[i] = buff[i]; //Heres was the CRASH //msg_username[i] = buff[i]; //Heres was the CRASH
//printk(KERN_INFO "Got %c at %d from %d bytes.\n", buff[i], i, (int)len); //printk(KERN_INFO "Got %c at %d from %d bytes.\n", buff[i], i, len);
}
for(i = len; i < USERBUF_LEN; i++) //Zeroing the rest of mem for(i = len; i < USERBUF_LEN; i++) //Zeroing the rest of mem
msg_username[i] = 0; msg_username[i] = 0;
printk(KERN_INFO "%s: Successfully got %d bytes!\n", printk(KERN_INFO "%s: Successfully got %d bytes!\n",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment