[PATCH phosphor-host-ipmid] ipmid crashing with simplified VERSION_ID
Andrew Jeffery
andrew at aj.id.au
Tue May 3 10:51:52 AEST 2016
On Sat, 2016-04-30 at 16:40 -0500, OpenBMC Patches wrote:
> From: Chris Austen <austenc at us.ibm.com>
>
> if the VERSION_ID is v0.1 instead of v0.1-1 then the code will crash. The fix is to always check
> for a NULL token each time.
Do we have a test suite? This kind of patch feels like it should come
with some tests so we don't break things in similar ways in the future.
Andrew
> ---
> apphandler.C | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/apphandler.C b/apphandler.C
> index 53a83d3..80f239c 100644
> --- a/apphandler.C
> +++ b/apphandler.C
> @@ -135,9 +135,18 @@ int convert_version(const char *p, rev_t *rev)
> // Capture the number of commits on top of the minor tag.
> // I'm using BE format like the ipmi spec asked for
> token = strtok(NULL,".-");
> - l = strlen(token);
> - if (l > 4)
> - l = 4;
> +
> + if (token) {
> + l = strlen(token);
> + if (l > 4)
> + l = 4;
> +
> + // commit number we skip
> + token = strtok(NULL,".-");
> +
> + } else {
> + l = 0;
> + }
>
> memset(hexbyte,'0', 4);
> memcpy(&hexbyte[4-l], token, l);
> @@ -146,12 +155,11 @@ int convert_version(const char *p, rev_t *rev)
>
> rev->d[2] = 0;
>
> - // commit number we skip
> - token = strtok(NULL,".-");
> -
> // Any value of the optional parameter forces it to 1
> - token = strtok(NULL,".-");
> - rev->d[3] = (token != NULL) ? 1 : 0;
> + if (token)
> + token = strtok(NULL,".-");
> +
> + rev->d[3] = (token != NULL) ? 1 : 0;
>
> free(s);
> return 0;
More information about the openbmc
mailing list