~vcs-imports/libssh/trunk

« back to all changes in this revision

Viewing changes to src/pki_crypto.c

  • Committer: Anderson Toshiyuki Sasaki
  • Date: 2019-10-07 09:41:30 UTC
  • Revision ID: git-v1:fe18ef279881b65434e3e44fc4743e4b1c7cb891
pki_crypto: Use temporary pointer when using i2d_*

These functions modify the provided pointer by advancing to the end of
if (point to the byte after the last written).  This makes the pointer
invalid, making necessary to use a temporary variable.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1642
1642
 
1643
1643
    int raw_sig_len = 0;
1644
1644
    unsigned char *raw_sig_data = NULL;
 
1645
    unsigned char *temp_raw_sig = NULL;
1645
1646
 
1646
1647
    int rc;
1647
1648
 
1700
1701
    ps = NULL;
1701
1702
    pr = NULL;
1702
1703
 
1703
 
    raw_sig_len = i2d_DSA_SIG(dsa_sig, &raw_sig_data);
1704
 
    if (raw_sig_len < 0) {
 
1704
    /* Get the expected size of the buffer */
 
1705
    rc = i2d_DSA_SIG(dsa_sig, NULL);
 
1706
    if (rc <= 0) {
 
1707
        goto error;
 
1708
    }
 
1709
    raw_sig_len = rc;
 
1710
 
 
1711
    raw_sig_data = (unsigned char *)calloc(1, raw_sig_len);
 
1712
    if (raw_sig_data == NULL) {
 
1713
        goto error;
 
1714
    }
 
1715
    temp_raw_sig = raw_sig_data;
 
1716
 
 
1717
    /* It is necessary to use a temporary pointer as i2d_* "advances" the
 
1718
     * pointer */
 
1719
    raw_sig_len = i2d_DSA_SIG(dsa_sig, &temp_raw_sig);
 
1720
    if (raw_sig_len <= 0) {
1705
1721
        goto error;
1706
1722
    }
1707
1723
 
1745
1761
    uint32_t rlen;
1746
1762
 
1747
1763
    unsigned char *raw_sig_data = NULL;
 
1764
    unsigned char *temp_raw_sig = NULL;
1748
1765
    size_t raw_sig_len = 0;
1749
1766
 
1750
1767
    int rc;
1820
1837
    pr = NULL;
1821
1838
    ps = NULL;
1822
1839
 
1823
 
    rc = i2d_ECDSA_SIG(ecdsa_sig, &raw_sig_data);
1824
 
    if (rc < 0) {
 
1840
    /* Get the expected size of the buffer */
 
1841
    rc = i2d_ECDSA_SIG(ecdsa_sig, NULL);
 
1842
    if (rc <= 0) {
1825
1843
        goto error;
1826
1844
    }
1827
1845
    raw_sig_len = rc;
1828
1846
 
 
1847
    raw_sig_data = (unsigned char *)calloc(1, raw_sig_len);
 
1848
    if (raw_sig_data == NULL) {
 
1849
        goto error;
 
1850
    }
 
1851
    temp_raw_sig = raw_sig_data;
 
1852
 
 
1853
    /* It is necessary to use a temporary pointer as i2d_* "advances" the
 
1854
     * pointer */
 
1855
    rc = i2d_ECDSA_SIG(ecdsa_sig, &temp_raw_sig);
 
1856
    if (rc <= 0) {
 
1857
        goto error;
 
1858
    }
 
1859
 
1829
1860
    sig->raw_sig = ssh_string_new(raw_sig_len);
1830
1861
    if (sig->raw_sig == NULL) {
1831
1862
        explicit_bzero(raw_sig_data, raw_sig_len);