poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Out of bounds check on pk_array* interface.


From: Jose E. Marchesi
Subject: Re: [PATCH] Out of bounds check on pk_array* interface.
Date: Thu, 02 Jul 2020 21:50:21 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Kostas.
This is OK for master.
Thanks!

    From: kostasch <sdi1600195@di.uoa.gr>
    Date: Thu, 2 Jul 2020 22:42:19 +0300
    
    2020-07-02  Kostas Chasialis  <sdi1600195@di.uoa.gr>
    
        * libpoke/libpoke.h (pk_array_elem_val): Prototype documentation
        now describes what happens in case invalid IDX is passed.
        (pk_array_set_elem_val): Likewise.
        (pk_array_elem_boffset): Likewise.
        (pk_array_set_elem_boffset): Likewise.
        * libpoke/pk-val.c (pk_array_elem_val): Check for IDX.
        (pk_array_set_elem_val): Likewise.
        (pk_array_elem_boffset): Likewise.
        (pk_array_set_elem_boffset): Likewise.
    
    ---
     ChangeLog         | 12 ++++++++++++
     libpoke/libpoke.h | 16 ++++++++++++----
     libpoke/pk-val.c  | 16 ++++++++++++----
     3 files changed, 36 insertions(+), 8 deletions(-)
    
    diff --git a/ChangeLog b/ChangeLog
    index 5392ccda..36fcdadb 100644
    --- a/ChangeLog
    +++ b/ChangeLog
    @@ -1,3 +1,15 @@
    +2020-07-02  Kostas Chasialis  <sdi1600195@di.uoa.gr>
    +
    +   * libpoke/libpoke.h (pk_array_elem_val): Prototype documentation
    +   now describes what happens in case invalid IDX is passed.
    +   (pk_array_set_elem_val): Likewise.
    +   (pk_array_elem_boffset): Likewise.
    +   (pk_array_set_elem_boffset): Likewise.
    +   * libpoke/pk-val.c (pk_array_elem_val): Check for IDX.
    +   (pk_array_set_elem_val): Likewise.
    +   (pk_array_elem_boffset): Likewise.
    +   (pk_array_set_elem_boffset): Likewise.
    +
     2020-07-02  Kostas Chasialis  <sdi1600195@di.uoa.gr>
     
        * etc/pk-mi-json-schema.json : JSON Schema
    diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
    index b44d6715..7b2c6691 100644
    --- a/libpoke/libpoke.h
    +++ b/libpoke/libpoke.h
    @@ -507,7 +507,9 @@ pk_val pk_array_nelem (pk_val array);
     /* Get the value of the element of an array.
     
        ARRAY is the array value.
    -   IDX is the index of the element in the array.  */
    +   IDX is the index of the element in the array.  
    +   
    +   If IDX is invalid, PK_NULL is returned. */
     
     pk_val pk_array_elem_val (pk_val array, uint64_t idx);
     
    @@ -518,7 +520,9 @@ pk_val pk_array_elem_val (pk_val array, uint64_t idx);
        VAL is the new value for the array element.
     
        Note that the type of the element is not checked by this function,
    -   so be careful.  */
    +   so be careful.  
    +   
    +   If IDX is invalid, array remains unchanged. */
     
     void pk_array_set_elem_val (pk_val array, uint64_t idx, pk_val val);
     
    @@ -528,7 +532,9 @@ void pk_array_set_elem_val (pk_val array, uint64_t idx, 
pk_val val);
        ARRAY is the array value.
        IDX is the index of the element in the array.
     
    -   The returned bit-offset is an uint<64>.  */
    +   The returned bit-offset is an uint<64>.  
    +   
    +   If IDX is invalid, PK_NULL is returned. */
     
     pk_val pk_array_elem_boffset (pk_val array, uint64_t idx);
     
    @@ -537,7 +543,9 @@ pk_val pk_array_elem_boffset (pk_val array, uint64_t 
idx);
     
        ARRAY is the array value.
        IDX is the index of the element in the array.
    -   BOFFSET is an uint<64> value with the bit-offset of the element.  */
    +   BOFFSET is an uint<64> value with the bit-offset of the element.  
    +   
    +   If IDX is invalid, array remains unchanged. */
     
     void pk_array_set_elem_boffset (pk_val array, uint64_t idx, pk_val 
boffset);
     
    diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c
    index 1722a4e6..3c333911 100644
    --- a/libpoke/pk-val.c
    +++ b/libpoke/pk-val.c
    @@ -269,23 +269,31 @@ pk_array_nelem (pk_val array)
     pk_val
     pk_array_elem_val (pk_val array, uint64_t idx)
     {
    -  return PVM_VAL_ARR_ELEM_VALUE (array, idx);
    +  if (idx < pk_uint_value (pk_array_nelem (array))) 
    +    return PVM_VAL_ARR_ELEM_VALUE (array, idx);
    +  else
    +    return PK_NULL;
     }
     
     void
     pk_array_set_elem_val (pk_val array, uint64_t idx, pk_val val)
     {
    -  PVM_VAL_ARR_ELEM_VALUE (array, idx) = val;
    +  if (idx < pk_uint_value (pk_array_nelem (array))) 
    +    PVM_VAL_ARR_ELEM_VALUE (array, idx) = val;
     }
     
     pk_val
     pk_array_elem_boffset (pk_val array, uint64_t idx)
     {
    -  return PVM_VAL_ARR_ELEM_OFFSET (array, idx);
    +  if (idx < pk_uint_value (pk_array_nelem (array))) 
    +    return PVM_VAL_ARR_ELEM_OFFSET (array, idx);
    +  else
    +    return PK_NULL;
     }
     
     void
     pk_array_set_elem_boffset (pk_val array, uint64_t idx, pk_val boffset)
     {
    -  PVM_VAL_ARR_ELEM_OFFSET (array, idx) = boffset;
    +  if (idx < pk_uint_value (pk_array_nelem (array))) 
    +    PVM_VAL_ARR_ELEM_OFFSET (array, idx) = boffset;
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]