Thanks Andy, I'm still learning(and will be over long period of time).
I hope I will have diffs for SF.net version of ipmitool by tomorrow.
Once finished, I will attach diffs to the filled bug at SF.net.

btw if I "understood" correctly, I have to put declaration of new function
into 'lib/helper.h' as well. This, however, has not been discussed here.

btw2 are return codes. Are positive numbers ok? I'm asking because
I've seen (-1) being returned on error. Shouldn't I return negative values
as well? Or it doesn't matter as long as return value is non-zero?
Despite question sounds a bit silly, it is rather C/ipmitool coding
standards one.

Z.


On Thu, Oct 27, 2011 at 3:37 PM, Andy Cress <andy.cr...@us.kontron.com> wrote:
> Zdenek,
>
> I would recommend two tweaks:
> - add "*uchr_ptr = 0;" after the NULL pointer/return 1 check, in case the 
> caller does not check the return value, at least the output byte will be 
> sane/default.
> - remove "|| arg_long < 0" before return 2, since arg_long is unsigned and 
> this could generate a compile warning
>
> Andy
>
> -----Original Message-----
> From: Zdenek Styblik [mailto:zdenek.styb...@gmail.com]
> Sent: Wednesday, October 26, 2011 3:09 PM
> To: ipmitool-devel
> Subject: Re: [Ipmitool-devel] multiple uint8_t overflow in 
> 'lib/ipmi_main.c'via parameters
>
> On Mon, Oct 24, 2011 at 8:25 PM, Zdenek Styblik
> <zdenek.styb...@gmail.com> wrote:
> [...]
>
> Ok, thanks to Andy's comments, here goes version 2.
>
> ~~~ 'lib/helper.c' ~~~
> #include <limits.h>
>
> [...]
>
> /* Desc: Convert array of chars into uint8_t and check for overflows
>  * @str: array of chars to parse from
>  * @uchr_ptr: pointer to address where uint8_t will be stored
>  */
> int str2uchar(char *str, uint8_t *uchr_ptr)
> {
>        uint32_t arg_long = 0;
>        char *end_ptr = 0;
>        if (!str || !uchr_ptr || sizeof(str) <= 0) {
>               /* Some of parameters to the function are missing or
> are invalid */
>                return 1;
>        }
>        errno = 0;
>        arg_long = strtoul(str, &end_ptr, 0);
>        if (*end_ptr != '\0' || errno != 0 || arg_long < 0) {
>                /* Invalid input given by user/overflow occurred */
>                return 2;
>        }
>        if (arg_long > UCHAR_MAX || arg_long == LONG_MIN || arg_long ==
> LONG_MAX) {
>                /* Given argument is too big to fit uint8_t */
>                return 3;
>        }
>        *uchr_ptr = (uint8_t) arg_long;
>        return 0;
> }
> ~~~ 'lib/helper.c' ~~~
>
> Zdenek
>
> ------------------------------------------------------------------------------
> The demand for IT networking professionals continues to grow, and the
> demand for specialized networking skills is growing even more rapidly.
> Take a complimentary Learning@Cisco Self-Assessment and learn
> about Cisco certifications, training, and career opportunities.
> http://p.sf.net/sfu/cisco-dev2dev
> _______________________________________________
> Ipmitool-devel mailing list
> Ipmitool-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
>

------------------------------------------------------------------------------
Get your Android app more play: Bring it to the BlackBerry PlayBook 
in minutes. BlackBerry App World&#153; now supports Android&#153; Apps 
for the BlackBerry&reg; PlayBook&#153;. Discover just how easy and simple 
it is! http://p.sf.net/sfu/android-dev2dev
_______________________________________________
Ipmitool-devel mailing list
Ipmitool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel

Reply via email to