[BACK]Return to sshbuf-getput-basic.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/sshbuf-getput-basic.c between version 1.7 and 1.8

version 1.7, 2017/06/01 04:51:58 version 1.8, 2019/07/14 23:32:27
Line 91 
Line 91 
         return 0;          return 0;
 }  }
   
   static int
   check_offset(const struct sshbuf *buf, int wr, size_t offset, size_t len)
   {
           if (sshbuf_ptr(buf) == NULL) /* calls sshbuf_check_sanity() */
                   return SSH_ERR_INTERNAL_ERROR;
           if (offset >= SIZE_MAX - len)
                   return SSH_ERR_INVALID_ARGUMENT;
           if (offset + len > sshbuf_len(buf)) {
                   return wr ?
                       SSH_ERR_NO_BUFFER_SPACE : SSH_ERR_MESSAGE_INCOMPLETE;
           }
           return 0;
   }
   
   static int
   check_roffset(const struct sshbuf *buf, size_t offset, size_t len,
       const u_char **p)
   {
           int r;
   
           *p = NULL;
           if ((r = check_offset(buf, 0, offset, len)) != 0)
                   return r;
           *p = sshbuf_ptr(buf) + offset;
           return 0;
   }
   
 int  int
   sshbuf_peek_u64(const struct sshbuf *buf, size_t offset, u_int64_t *valp)
   {
           const u_char *p = NULL;
           int r;
   
           if (valp != NULL)
                   *valp = 0;
           if ((r = check_roffset(buf, offset, 8, &p)) != 0)
                   return r;
           if (valp != NULL)
                   *valp = PEEK_U64(p);
           return 0;
   }
   
   int
   sshbuf_peek_u32(const struct sshbuf *buf, size_t offset, u_int32_t *valp)
   {
           const u_char *p = NULL;
           int r;
   
           if (valp != NULL)
                   *valp = 0;
           if ((r = check_roffset(buf, offset, 4, &p)) != 0)
                   return r;
           if (valp != NULL)
                   *valp = PEEK_U32(p);
           return 0;
   }
   
   int
   sshbuf_peek_u16(const struct sshbuf *buf, size_t offset, u_int16_t *valp)
   {
           const u_char *p = NULL;
           int r;
   
           if (valp != NULL)
                   *valp = 0;
           if ((r = check_roffset(buf, offset, 2, &p)) != 0)
                   return r;
           if (valp != NULL)
                   *valp = PEEK_U16(p);
           return 0;
   }
   
   int
   sshbuf_peek_u8(const struct sshbuf *buf, size_t offset, u_char *valp)
   {
           const u_char *p = NULL;
           int r;
   
           if (valp != NULL)
                   *valp = 0;
           if ((r = check_roffset(buf, offset, 1, &p)) != 0)
                   return r;
           if (valp != NULL)
                   *valp = *p;
           return 0;
   }
   
   int
 sshbuf_get_string(struct sshbuf *buf, u_char **valp, size_t *lenp)  sshbuf_get_string(struct sshbuf *buf, u_char **valp, size_t *lenp)
 {  {
         const u_char *val;          const u_char *val;
Line 339 
Line 426 
         if ((r = sshbuf_reserve(buf, 1, &p)) < 0)          if ((r = sshbuf_reserve(buf, 1, &p)) < 0)
                 return r;                  return r;
         p[0] = val;          p[0] = val;
           return 0;
   }
   
   static int
   check_woffset(struct sshbuf *buf, size_t offset, size_t len, u_char **p)
   {
           int r;
   
           *p = NULL;
           if ((r = check_offset(buf, 1, offset, len)) != 0)
                   return r;
           if (sshbuf_mutable_ptr(buf) == NULL)
                   return SSH_ERR_BUFFER_READ_ONLY;
           *p = sshbuf_mutable_ptr(buf) + offset;
           return 0;
   }
   
   int
   sshbuf_poke_u64(struct sshbuf *buf, size_t offset, u_int64_t val)
   {
           u_char *p = NULL;
           int r;
   
           if ((r = check_woffset(buf, offset, 8, &p)) != 0)
                   return r;
           POKE_U64(p, val);
           return 0;
   }
   
   int
   sshbuf_poke_u32(struct sshbuf *buf, size_t offset, u_int32_t val)
   {
           u_char *p = NULL;
           int r;
   
           if ((r = check_woffset(buf, offset, 4, &p)) != 0)
                   return r;
           POKE_U32(p, val);
           return 0;
   }
   
   int
   sshbuf_poke_u16(struct sshbuf *buf, size_t offset, u_int16_t val)
   {
           u_char *p = NULL;
           int r;
   
           if ((r = check_woffset(buf, offset, 2, &p)) != 0)
                   return r;
           POKE_U16(p, val);
           return 0;
   }
   
   int
   sshbuf_poke_u8(struct sshbuf *buf, size_t offset, u_char val)
   {
           u_char *p = NULL;
           int r;
   
           if ((r = check_woffset(buf, offset, 1, &p)) != 0)
                   return r;
           *p = val;
           return 0;
   }
   
   int
   sshbuf_poke(struct sshbuf *buf, size_t offset, void *v, size_t len)
   {
           u_char *p = NULL;
           int r;
   
           if ((r = check_woffset(buf, offset, len, &p)) != 0)
                   return r;
           memcpy(p, v, len);
         return 0;          return 0;
 }  }
   

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8