Re: [PATCH] USERSPACE: usr/strings.c: check NULL pointer first and add limit check in str_remove_initial
On 2011年08月19日 01:03, Mike Christie wrote: heck NULL pointer first before reference its member, and check the limit on the data buffer in function str_remove_initial. Signed-off-by: Wang Sheng-Hui shh...@gmail.com --- usr/strings.c | 13 + 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { -char *remaining = s-buffer + length; -int amount = s-data_length - length; - -if (s length) { -memmove(s-buffer, remaining, amount); + char *remaining; + int amount; + + if (s length) { +remaining = s-buffer + length; +amount = s-data_length - length; + if (amount 0) + amount = 0; + if (amount) +memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; } For the tabs did you do spacebar 8 times or did you set your editor to use 8 spaces for the tabs? I am asking because it seems that the tabs got turned to spaces and I am trying to figure out if my mailer messed it up. I just did set ts=8 in vim. I will just fix it up on my side when I merge it. Thanks for the patch. -- You received this message because you are subscribed to the Google Groups open-iscsi group. To post to this group, send email to open-iscsi@googlegroups.com. To unsubscribe from this group, send email to open-iscsi+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
Re: [PATCH] USERSPACE: usr/strings.c: check NULL pointer first and add limit check in str_remove_initial
On 2011年08月18日 04:38, Mike Christie wrote: Did you actually hit this or just find it by searching the code? I found it while I'm reading its source code. Do I need to regenerate the patch? On 08/15/2011 07:37 PM, Wang Sheng-Hui wrote: diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { -char *remaining = s-buffer + length; -int amount = s-data_length - length; - -if (s length) { -memmove(s-buffer, remaining, amount); +char *remaining; +int amount; + +if (s length) { +remaining = s-buffer + length; +amount = s-data_length - length; +if (amount 0) +amount = 0; The formatting is off. We use 8 space tabs. So all this above needs to be tabbed over properly. Check out str_truncate_buffer below this function for an example or following the tabbing used in the function originally. Also after the if line then the next line should be tabbed over and not alinged with the (. +if (amount) +memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; So you can tell here the formatting is really off. The old code uses the old tabbing and so it makes it akward to read. Patch looks ok other than that. -- You received this message because you are subscribed to the Google Groups open-iscsi group. To post to this group, send email to open-iscsi@googlegroups.com. To unsubscribe from this group, send email to open-iscsi+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
Re: [PATCH] USERSPACE: usr/strings.c: check NULL pointer first and add limit check in str_remove_initial
On 2011年08月18日 10:03, Wang Sheng-Hui wrote: On 2011年08月18日 04:38, Mike Christie wrote: Did you actually hit this or just find it by searching the code? I found it while I'm reading its source code. Do I need to regenerate the patch? On 08/15/2011 07:37 PM, Wang Sheng-Hui wrote: diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { - char *remaining = s-buffer + length; - int amount = s-data_length - length; - - if (s length) { - memmove(s-buffer, remaining, amount); +char *remaining; +int amount; + +if (s length) { + remaining = s-buffer + length; + amount = s-data_length - length; +if (amount 0) +amount = 0; The formatting is off. We use 8 space tabs. So all this above needs to be tabbed over properly. Check out str_truncate_buffer below this function for an example or following the tabbing used in the function originally. Also after the if line then the next line should be tabbed over and not alinged with the (. +if (amount) + memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; So you can tell here the formatting is really off. The old code uses the old tabbing and so it makes it akward to read. Patch looks ok other than that. patch regenerated to use 8 space tabs. Hope it's in right intent this time. - We should check NULL pointer first before reference its member, and check the limit on the data buffer in function str_remove_initial. Signed-off-by: Wang Sheng-Hui shh...@gmail.com --- usr/strings.c | 13 + 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { - char *remaining = s-buffer + length; - int amount = s-data_length - length; - - if (s length) { - memmove(s-buffer, remaining, amount); + char *remaining; + int amount; + + if (s length) { + remaining = s-buffer + length; + amount = s-data_length - length; + if (amount 0) + amount = 0; + if (amount) + memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; } -- 1.7.1 -- You received this message because you are subscribed to the Google Groups open-iscsi group. To post to this group, send email to open-iscsi@googlegroups.com. To unsubscribe from this group, send email to open-iscsi+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
Re: [PATCH] USERSPACE: usr/strings.c: check NULL pointer first and add limit check in str_remove_initial
heck NULL pointer first before reference its member, and check the limit on the data buffer in function str_remove_initial. Signed-off-by: Wang Sheng-Hui shh...@gmail.com --- usr/strings.c | 13 + 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { - char *remaining = s-buffer + length; - int amount = s-data_length - length; - - if (s length) { - memmove(s-buffer, remaining, amount); + char *remaining; + int amount; + + if (s length) { + remaining = s-buffer + length; + amount = s-data_length - length; + if (amount 0) + amount = 0; + if (amount) + memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; } For the tabs did you do spacebar 8 times or did you set your editor to use 8 spaces for the tabs? I am asking because it seems that the tabs got turned to spaces and I am trying to figure out if my mailer messed it up. I will just fix it up on my side when I merge it. Thanks for the patch. -- You received this message because you are subscribed to the Google Groups open-iscsi group. To post to this group, send email to open-iscsi@googlegroups.com. To unsubscribe from this group, send email to open-iscsi+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
Re: [PATCH] USERSPACE: usr/strings.c: check NULL pointer first and add limit check in str_remove_initial
Did you actually hit this or just find it by searching the code? On 08/15/2011 07:37 PM, Wang Sheng-Hui wrote: diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { - char *remaining = s-buffer + length; - int amount = s-data_length - length; - - if (s length) { - memmove(s-buffer, remaining, amount); +char *remaining; +int amount; + +if (s length) { + remaining = s-buffer + length; + amount = s-data_length - length; +if (amount 0) +amount = 0; The formatting is off. We use 8 space tabs. So all this above needs to be tabbed over properly. Check out str_truncate_buffer below this function for an example or following the tabbing used in the function originally. Also after the if line then the next line should be tabbed over and not alinged with the (. +if (amount) + memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; So you can tell here the formatting is really off. The old code uses the old tabbing and so it makes it akward to read. Patch looks ok other than that. -- You received this message because you are subscribed to the Google Groups open-iscsi group. To post to this group, send email to open-iscsi@googlegroups.com. To unsubscribe from this group, send email to open-iscsi+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.
[PATCH] USERSPACE: usr/strings.c: check NULL pointer first and add limit check in str_remove_initial
We should check NULL pointer first before reference its member, and check the limit on the data buffer in function str_remove_initial. Signed-off-by: Wang Sheng-Hui shh...@gmail.com --- usr/strings.c | 13 + 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/usr/strings.c b/usr/strings.c index ee6a51c..6432c2c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -97,11 +97,16 @@ int str_enlarge_data(struct str_buffer *s, int length) void str_remove_initial(struct str_buffer *s, int length) { - char *remaining = s-buffer + length; - int amount = s-data_length - length; - - if (s length) { - memmove(s-buffer, remaining, amount); +char *remaining; +int amount; + +if (s length) { + remaining = s-buffer + length; + amount = s-data_length - length; +if (amount 0) +amount = 0; +if (amount) + memmove(s-buffer, remaining, amount); s-data_length = amount; s-buffer[amount] = '\0'; } -- 1.7.1 -- You received this message because you are subscribed to the Google Groups open-iscsi group. To post to this group, send email to open-iscsi@googlegroups.com. To unsubscribe from this group, send email to open-iscsi+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/open-iscsi?hl=en.