mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-25 09:41:47 +08:00
Fix the buffer length may cause a read error
Since The length of the message buffer is BUF_LEN. When writing the BUF_LEN length of the string it will overwrite the last character (usually it is '\0' from the initialization). And, because the read operation uses the character in the message buffer ('\0') to stop the read loop. It will cause the read operation will read out of the message buffer when the length parameter of read() is not lower than or equal to BUF_LEN. So add one more byte space to avoid this problem.
This commit is contained in:
parent
637e707a1a
commit
95a7ca513f
|
@ -36,7 +36,7 @@ enum {
|
|||
/* Is device open? Used to prevent multiple access to device */
|
||||
static atomic_t already_open = ATOMIC_INIT(CDEV_NOT_USED);
|
||||
|
||||
static char msg[BUF_LEN]; /* The msg the device will give when asked */
|
||||
static char msg[BUF_LEN + 1]; /* The msg the device will give when asked */
|
||||
|
||||
static struct class *cls;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ enum {
|
|||
static atomic_t already_open = ATOMIC_INIT(CDEV_NOT_USED);
|
||||
|
||||
/* The message the device will give when asked */
|
||||
static char message[BUF_LEN];
|
||||
static char message[BUF_LEN + 1];
|
||||
|
||||
static struct class *cls;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user