kernel/irq/proc.c: set MAX_NAMELEN 11 instead of 10 which express the maximize size of "%d" or "%u".
PATCH 1/1 kernel/irq/proc.c: set MAX_NAMELEN 11 instead of 10 which express the maximize size of "%d" or "%u".
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set MAX_NAMELEN 11 instead of 10.
In real world, it may not cause issue, but still recommend to fix this 'theoretical' bug (especially original definition already considered about 'theoretical' using).
--- kernel/irq/proc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/irq/proc.c +1 -1
@@ -305,7 +305,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)#undef MAX_NAMELEN -#define MAX_NAMELEN 10 +#define MAX_NAMELEN 11void register_irq_proc (unsigned int irq,struct irq_desc *desc) {
Signature · 1 line
1.7.7.
Hello Al Viro:
Is this patch correct? ;-)
Thanks.
Quoted 26 lines · Chen Gang
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.In real world, it may not cause issue, but still recommend to fix this 'theoretical' bug (especially original definition already considered about 'theoretical' using).
Signed-off-by Chen Gang <[email protected]>--- kernel/irq/proc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/irq/proc.c +1
-1@@ -305,7 +305,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)#undef MAX_NAMELEN -#define MAX_NAMELEN 10 +#define MAX_NAMELEN 11void register_irq_proc (unsigned int irq,struct irq_desc *desc) {
Signature · 1 line
Chen Gang
Quoted 2 lines · Chen Gang
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.
%d can be negative.
Quoted 9 lines · Joe Perches
Quoted 2 lines · Chen Gang
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Oh, really, it is incorrect. Al Viro succeeds once. :-(
And I should send patch v2 for it.
Thanks.
Signature · 1 line
Chen Gang
Quoted 11 lines · Chen Gang
Quoted 9 lines · Joe Perches
Quoted 2 lines · Chen Gang
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Quoted 3 lines
Oh, really, it is incorrect. Al Viro succeeds once. :-(
And I should send patch v2 for it.
irq is in both register_irq_proc() and unregister_irq_proc() an unsigned int. Therefore %d makes not really sense. Both should use %u.
IMHO sprintf() should also get replaced by snprintf() but that's a matter of taste.
Signature · 2 lines
Thanks, //richard
Quoted 12 lines · Richard Weinberger
Quoted 11 lines · Chen Gang
Quoted 9 lines · Joe Perches
Quoted 2 lines · Chen Gang
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Quoted 9 lines
Quoted 3 lines
Oh, really, it is incorrect. Al Viro succeeds once. :-(
And I should send patch v2 for it.
irq is in both
register_irq_proc()andunregister_irq_proc()an unsigned int. Therefore %d makes not really sense. Both should use %u.
IMHOsprintf()should also get replaced bysnprintf()but that's a matter of taste.
OK, thanks. your opinions sounds more reasonable to me.
After 1 day (if no additional reply), I should send patch v2 for it.
Thanks
Signature · 1 line
Chen Gang
Quoted 15 lines · Chen Gang
Quoted 14 lines · Richard Weinberger
Quoted 13 lines · Chen Gang
Quoted 9 lines · Joe Perches
Quoted 2 lines · Chen Gang
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Oh, really, it is incorrect. Al Viro succeeds once. :-(
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
And I should send patch v2 for it.
irq is in both
register_irq_proc()andunregister_irq_proc()an unsigned int. Therefore %d makes not really sense. Both should use %u.
IMHOsprintf()should also get replaced bysnprintf()but that's a matter of taste.
Oh, commonly, snprintf() are used for the string which can be truncated, and can not be used for the string which contents must not be truncated.
In our case, the name string must be not truncated (or may not unique, theoretically), so we have to still use sprintf().
Thanks.
Quoted 8 lines
OK, thanks. your opinions sounds more reasonable to me.
After 1 day (if no additional reply), I should send patch v2 for it.
Thanks
Signature · 1 line
Chen Gang
Am 05.10.2013 19:06, schrieb Chen Gang:
Quoted 24 lines · Chen Gang
Quoted 15 lines · Richard Weinberger
Quoted 14 lines · Chen Gang
Quoted 13 lines · Joe Perches
Quoted 9 lines · Chen Gang
Quoted 2 lines
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Oh, really, it is incorrect. Al Viro succeeds once. :-(
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
And I should send patch v2 for it.
irq is in both
register_irq_proc()andunregister_irq_proc()an unsigned int. Therefore %d makes not really sense. Both should use %u.
IMHOsprintf()should also get replaced bysnprintf()but that's a matter of taste.
Quoted 5 lines
Oh, commonly,
snprintf()are used for the string which can be truncated, and can not be used for the string which contents must not be truncated.In our case, the name string must be not truncated (or may not unique, theoretically), so we have to still use
sprintf().
Of course you would have to check the return value of snprintf() to detect a truncation and abort...
Thanks,
//richard
Quoted 25 lines · Richard Weinberger
Am 05.10.2013 19:06, schrieb Chen Gang:
Quoted 24 lines · Chen Gang
Quoted 22 lines · Richard Weinberger
Quoted 21 lines · Chen Gang
Quoted 11 lines · Joe Perches
Quoted 9 lines · Chen Gang
Quoted 2 lines
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Quoted 3 lines
Oh, really, it is incorrect. Al Viro succeeds once. :-(
And I should send patch v2 for it.
irq is in both
register_irq_proc()andunregister_irq_proc()an unsigned int. Therefore %d makes not really sense. Both should use %u.
IMHOsprintf()should also get replaced bysnprintf()but that's a matter of taste.
Quoted 9 lines
Quoted 5 lines
Oh, commonly,
snprintf()are used for the string which can be truncated, and can not be used for the string which contents must not be truncated.In our case, the name string must be not truncated (or may not unique, theoretically), so we have to still use
sprintf().Of course you would have to check the return value of
snprintf()to detect a truncation and abort...
OK, thanks, that sounds reasonable to me, so I feel that's not a matter of taste.
In my opinion, when we know the maximized length, we need always use s(c)nprintf instead of sprintf, if the string can be truncated, use scnprintf, else use snprintf and also check the return value.
sprintf is 'dangrous', need try to use s(c)nprintf instead of. We can scan whole kernel, I guess quite a few of sprintf may be related with memory overflow 'theoretically' (welcome any members to give a check).
Thanks.
Quoted 5 lines
Thanks,
//richard
Signature · 1 line
Chen Gang
Quoted 32 lines · Chen Gang
Quoted 31 lines · Richard Weinberger
Am 05.10.2013 19:06, schrieb Chen Gang:
Quoted 29 lines · Chen Gang
Quoted 15 lines · Richard Weinberger
Quoted 14 lines · Chen Gang
Quoted 13 lines · Joe Perches
Quoted 9 lines · Chen Gang
Quoted 2 lines
Theoretically, the maximize size of "%d" or "%u" is 11 (10 + '\0'), so need set
MAX_NAMELEN11 instead of 10.%d can be negative.
Oh, really, it is incorrect. Al Viro succeeds once. :-(
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
And I should send patch v2 for it.
irq is in both
register_irq_proc()andunregister_irq_proc()an unsigned int. Therefore %d makes not really sense. Both should use %u.
IMHOsprintf()should also get replaced bysnprintf()but that's a matter of taste.Oh, commonly,
snprintf()are used for the string which can be truncated, and can not be used for the string which contents must not be truncated.In our case, the name string must be not truncated (or may not unique, theoretically), so we have to still use
sprintf().
Quoted 7 lines
Quoted 3 lines
Of course you would have to check the return value of
snprintf()to detect a truncation and abort...OK, thanks, that sounds reasonable to me, so I feel that's not a matter of taste.
Hmm... does 'taste' means: "for string which can not be truncated, if maximized length is obvious (e.g. our case 11 for "%u"), sprintf() is more clearer than snprintf() for both readers and writers"?
BTW: when MAX_NAMELEN is defined as 128, is it suitable to check the return value of snprintf() in register_handler_proc(), and WARN_ON() if it is not less than 128?
Thanks.
Quoted 17 lines
In my opinion, when we know the maximized length, we need always use s(c)nprintf instead of sprintf, if the string can be truncated, use scnprintf, else use snprintf and also check the return value.
sprintf is 'dangrous', need try to use s(c)nprintf instead of. We can scan whole kernel, I guess quite a few of sprintf may be related with memory overflow 'theoretically' (welcome any members to give a check).
Thanks.
Quoted 5 lines
Thanks,
//richard
Signature · 1 line
Chen Gang
PATCH v2 1/1 kernel/irq/proc.c: set MAX_NAMELEN 11 instead of 10 and use "%u" instead of "%d" for printing 'irq'
Theoretically, the maximize size of "%u" is 11 (10 + '\0'), so need set MAX_NAMELEN 11 instead of 10, and also 'irq' is unsigned int, so need use "%u" instead of "%d".
In real world, it may not cause issue, but still recommend to fix the 'theoretical' bugs (especially original definition already considered about 'theoretical' using).
--- kernel/irq/proc.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/irq/proc.c +2 -2
@@ -305,7 +305,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)#undef MAX_NAMELEN -#define MAX_NAMELEN 10 +#define MAX_NAMELEN 11void register_irq_proc (unsigned int irq,struct irq_desc *desc) {
@@ -315,7 +315,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)return ;memset (name,0 ,MAX_NAMELEN ); -sprintf (name,"%d" , irq); +sprintf (name,"%u" , irq);/* create /proc/irq/1234 */ desc->dir =proc_mkdir (name, root_irq_dir);
Signature · 1 line
1.7.7.6