Commit 8dd1c8a
authored
Copy only received bytes from socket recv buffer into the app buffer (#1497)
**What**
* Updated `copy_buffer_to_iovec_app` so that it copies as much of the buffer into the iovec as specified
* Throw invalid value when allocating an iovec of size 0
**Why**
* A bug found from TCP client example which allocates 1024 for the iovec size (where the buf size is also 1024) but received bytes is passed in as the `buf_size` argument to `copy_buffer_to_iovec_app`. This would return early after hitting this check `buf + data->buf_len > buf_begin + buf_size`. However, if the amount to copy is less than the iovec size, we should copy that much of the buf size. Eg TCP client sample receives 27(?) bytes at a time, and this copies 27 bytes into the iovec of size 1024
* The TCP client example attempts to recv bytes of size 0, this attempts to wasm malloc size 0, which outputs a warning. We should early return if recv bytes of size 01 parent c072b51 commit 8dd1c8a
File tree
2 files changed
+35
-6
lines changed- core/iwasm/libraries/libc-wasi
- samples/socket-api
2 files changed
+35
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1841 | 1841 | | |
1842 | 1842 | | |
1843 | 1843 | | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
1844 | 1849 | | |
1845 | 1850 | | |
1846 | 1851 | | |
| |||
1852 | 1857 | | |
1853 | 1858 | | |
1854 | 1859 | | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
1855 | 1866 | | |
1856 | 1867 | | |
1857 | | - | |
| 1868 | + | |
| 1869 | + | |
1858 | 1870 | | |
1859 | 1871 | | |
1860 | 1872 | | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
1861 | 1878 | | |
1862 | 1879 | | |
1863 | 1880 | | |
| |||
1868 | 1885 | | |
1869 | 1886 | | |
1870 | 1887 | | |
1871 | | - | |
| 1888 | + | |
| 1889 | + | |
1872 | 1890 | | |
1873 | 1891 | | |
1874 | 1892 | | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
1875 | 1900 | | |
1876 | | - | |
1877 | | - | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
1878 | 1905 | | |
1879 | 1906 | | |
1880 | 1907 | | |
| |||
1921 | 1948 | | |
1922 | 1949 | | |
1923 | 1950 | | |
1924 | | - | |
1925 | | - | |
| 1951 | + | |
| 1952 | + | |
1926 | 1953 | | |
1927 | 1954 | | |
1928 | 1955 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| 94 | + | |
| 95 | + | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
| |||
0 commit comments