lib: fix callers of strtobool to use char array
Subsystems (5)
PATCH 1/1 lib: fix callers of strtobool to use char array
Some callers of strtobool were passing a pointer to unterminated strings. This fixes the issue and consolidates some logic in cifs.
---
This is preparation for adding "on"/"off" support to strtobool(), and I want to make sure the solution isn't upsetting to the two callers. :)
--- drivers/net/wireless/marvell/mwifiex/debugfs.c | 6 +- fs/cifs/cifs_debug.c | 78 ++++++++++++-------------- fs/cifs/cifs_debug.h | 2 +- fs/cifs/cifsfs.c | 6 +- fs/cifs/cifsglob.h | 4 +- 5 files changed, 44 insertions(+), 52 deletions(-)
drivers/net/wireless/marvell/mwifiex/debugfs.c +3 -3
@@ -880,13 +880,13 @@ mwifiex_reset_write(struct file *file, {struct mwifiex_private *priv = file->private_data;struct mwifiex_adapter *adapter = priv->adapter; -char cmd; +char cmd[2 ] = {'\0' };bool result; -if (copy_from_user (&cmd, ubuf,sizeof (cmd))) +if (copy_from_user (cmd, ubuf,sizeof (char )))return -EFAULT ; -if (strtobool (&cmd, &result)) +if (strtobool (cmd, &result))return -EINVAL ;if (!result)
fs/cifs/cifs_debug.c +35 -43
159 lines not on this page · raw message
fs/cifs/cifs_debug.h +1 -1
@@ -25,7 +25,7 @@void cifs_dump_mem (char *label,void *data,int length);void cifs_dump_detail (void *);void cifs_dump_mids (struct TCP_Server_Info *); -extern int traceSMB;/* flag which enables the function below */ +extern bool traceSMB;/* flag which enables the function below */ void dump_smb (void *,int );#define CIFS_INFO 0x01#define CIFS_RC 0x02
fs/cifs/cifsfs.c +3 -3
@@ -54,10 +54,10 @@#endif int cifsFYI =0 ; -int traceSMB =0 ; +bool traceSMB;bool enable_oplocks = true; -unsigned int linuxExtEnabled =1 ; -unsigned int lookupCacheEnabled =1 ; +bool linuxExtEnabled = true; +bool lookupCacheEnabled = true;unsigned int global_secflags =CIFSSEC_DEF ;/* unsigned int ntlmv2_support = 0; */ unsigned int sign_CIFS_PDUs =1 ;
fs/cifs/cifsglob.h +2 -2
@@ -1596,11 +1596,11 @@ GLOBAL_EXTERN atomic_t midCount;/* Misc globals */ GLOBAL_EXTERN bool enable_oplocks; /* enable or disable oplocks */ -GLOBAL_EXTERN unsigned int lookupCacheEnabled; +GLOBAL_EXTERN bool lookupCacheEnabled; GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sentwith more secure ntlmssp2 challenge/resp */ GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */ -GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ +GLOBAL_EXTERN bool linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/ GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */ GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */ GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
Signature · 6 lines
2.6.3 -- Kees Cook Chrome OS & Brillo Security
Quoted 2 lines · Kees Cook
Some callers of strtobool were passing a pointer to unterminated strings. This fixes the issue and consolidates some logic in cifs.
This may be incomplete as it duplicates the behavior for the old number of characters, but this is not a solution for the entry of a bool that is "on" or "off".
fs/cifs/cifs_debug.c
Quoted 1 line
fs/cifs/cifs_debug.c +0
-0
[]
fs/cifs/cifs_debug.c static ssize_t cifs_stats_proc_write(struct file *file, · line 309
Quoted 7 lines
fs/cifs/cifs_debug.c +2
-1@@ -290,7 +305,8 @@ static ssize_t cifs_stats_proc_write(struct file *file, } } spin_unlock(&cifs_tcp_ses_lock); - } + }else +return rc;
Likely better to reverse the test and unindent the preceding block.
Otherwise, please make sure to use the general brace form of when one branch needs braces, the other branch should have them too.
Quoted 7 lines · Joe Perches
Quoted 2 lines · Kees Cook
Some callers of strtobool were passing a pointer to unterminated strings. This fixes the issue and consolidates some logic in cifs.
This may be incomplete as it duplicates the behavior for the old number of characters, but this is not a solution for the entry of a bool that is "on" or "off".
As in, the on/off patch is missing? Yes, that's been sent separately, but I wanted to make sure these changes weren't upsetting to the two users.
Quoted 13 lines
fs/cifs/cifs_debug.c
Quoted 1 line
fs/cifs/cifs_debug.c +0
-0[]
fs/cifs/cifs_debug.c static ssize_t cifs_stats_proc_write(struct file *file, · line 309
Quoted 7 lines
fs/cifs/cifs_debug.c +2
-1@@ -290,7 +305,8 @@ static ssize_t cifs_stats_proc_write(struct file *file, } }spin_unlock (&cifs_tcp_ses_lock); - } + }else +return rc;Likely better to reverse the test and unindent the preceding block.
Quoted 3 lines
Otherwise, please make sure to use the general brace form of when one branch needs braces, the other branch should have them too.
Okay, sure, I'll rework this and send it together with the on/off patch.
-Kees
Signature · 2 lines
Kees Cook Chrome OS & Brillo Security