aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2023-09-11 19:48:04 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2023-09-11 19:50:20 +0300
commit97707d77b7ed96b9c838afde37ae97e54bfcada1 (patch)
tree54a2ad060da398d2d2072c41b49b005b4edbb06d
parent35cfb56e7d4d7a950cb8e7b68c68b9cb81064e90 (diff)
downloadlibmicrohttpd-97707d77b7ed96b9c838afde37ae97e54bfcada1.tar.gz
libmicrohttpd-97707d77b7ed96b9c838afde37ae97e54bfcada1.zip
mhd_str: fixed possible compiler and run-time sanitizers warnings
-rw-r--r--src/microhttpd/mhd_str.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index d32efc02..2504d366 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1293,8 +1293,8 @@ MHD_strx_to_uint32_ (const char *str,
1293 while (digit >= 0) 1293 while (digit >= 0)
1294 { 1294 {
1295 if ( (res < (UINT32_MAX / 16)) || 1295 if ( (res < (UINT32_MAX / 16)) ||
1296 ((res == (UINT32_MAX / 16)) && ( (uint32_t) digit <= (UINT32_MAX 1296 ((res == (UINT32_MAX / 16)) &&
1297 % 16)) ) ) 1297 ( (uint32_t) digit <= (UINT32_MAX % 16)) ) )
1298 { 1298 {
1299 res *= 16; 1299 res *= 16;
1300 res += (unsigned int) digit; 1300 res += (unsigned int) digit;
@@ -1340,8 +1340,8 @@ MHD_strx_to_uint32_n_ (const char *str,
1340 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 1340 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
1341 { 1341 {
1342 if ( (res > (UINT32_MAX / 16)) || 1342 if ( (res > (UINT32_MAX / 16)) ||
1343 ((res == (UINT32_MAX / 16)) && ( (uint32_t) digit > (UINT32_MAX 1343 ((res == (UINT32_MAX / 16)) &&
1344 % 16)) ) ) 1344 ( (uint32_t) digit > (UINT32_MAX % 16)) ) )
1345 return 0; 1345 return 0;
1346 1346
1347 res *= 16; 1347 res *= 16;
@@ -1380,8 +1380,8 @@ MHD_strx_to_uint64_ (const char *str,
1380 while (digit >= 0) 1380 while (digit >= 0)
1381 { 1381 {
1382 if ( (res < (UINT64_MAX / 16)) || 1382 if ( (res < (UINT64_MAX / 16)) ||
1383 ((res == (UINT64_MAX / 16)) && ( (uint64_t) digit <= (UINT64_MAX 1383 ((res == (UINT64_MAX / 16)) &&
1384 % 16)) ) ) 1384 ( (uint64_t) digit <= (UINT64_MAX % 16)) ) )
1385 { 1385 {
1386 res *= 16; 1386 res *= 16;
1387 res += (unsigned int) digit; 1387 res += (unsigned int) digit;
@@ -1427,8 +1427,8 @@ MHD_strx_to_uint64_n_ (const char *str,
1427 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0) 1427 while (i < maxlen && (digit = toxdigitvalue (str[i])) >= 0)
1428 { 1428 {
1429 if ( (res > (UINT64_MAX / 16)) || 1429 if ( (res > (UINT64_MAX / 16)) ||
1430 ((res == (UINT64_MAX / 16)) && ( (uint64_t) digit > (UINT64_MAX 1430 ((res == (UINT64_MAX / 16)) &&
1431 % 16)) ) ) 1431 ( (uint64_t) digit > (UINT64_MAX % 16)) ) )
1432 return 0; 1432 return 0;
1433 1433
1434 res *= 16; 1434 res *= 16;
@@ -1777,8 +1777,9 @@ MHD_str_pct_decode_strict_n_ (const char *pct_encoded,
1777 unsigned char out; 1777 unsigned char out;
1778 if ((0 > h) || (0 > l)) 1778 if ((0 > h) || (0 > l))
1779 return 0; 1779 return 0;
1780 out = (unsigned char) ( (((uint8_t) ((unsigned int) h)) << 4) 1780 out =
1781 | ((uint8_t) ((unsigned int) l)) ); 1781 (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4))
1782 | ((uint8_t) ((unsigned int) l)));
1782 decoded[w] = (char) out; 1783 decoded[w] = (char) out;
1783 } 1784 }
1784 } 1785 }
@@ -1806,8 +1807,9 @@ MHD_str_pct_decode_strict_n_ (const char *pct_encoded,
1806 unsigned char out; 1807 unsigned char out;
1807 if ((0 > h) || (0 > l)) 1808 if ((0 > h) || (0 > l))
1808 return 0; 1809 return 0;
1809 out = (unsigned char) ( (((uint8_t) ((unsigned int) h)) << 4) 1810 out =
1810 | ((uint8_t) ((unsigned int) l)) ); 1811 (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4))
1812 | ((uint8_t) ((unsigned int) l)));
1811 decoded[w] = (char) out; 1813 decoded[w] = (char) out;
1812 } 1814 }
1813 } 1815 }
@@ -1862,8 +1864,9 @@ MHD_str_pct_decode_lenient_n_ (const char *pct_encoded,
1862 } 1864 }
1863 else 1865 else
1864 { 1866 {
1865 out = (unsigned char) ( (((uint8_t) ((unsigned int) h)) << 4) 1867 out =
1866 | ((uint8_t) ((unsigned int) l)) ); 1868 (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4))
1869 | ((uint8_t) ((unsigned int) l)));
1867 decoded[w] = (char) out; 1870 decoded[w] = (char) out;
1868 } 1871 }
1869 } 1872 }
@@ -1903,8 +1906,9 @@ MHD_str_pct_decode_lenient_n_ (const char *pct_encoded,
1903 else 1906 else
1904 { 1907 {
1905 unsigned char out; 1908 unsigned char out;
1906 out = (unsigned char) ( (((uint8_t) ((unsigned int) h)) << 4) 1909 out =
1907 | ((uint8_t) ((unsigned int) l)) ); 1910 (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4))
1911 | ((uint8_t) ((unsigned int) l)));
1908 decoded[w] = (char) out; 1912 decoded[w] = (char) out;
1909 } 1913 }
1910 } 1914 }
@@ -1958,8 +1962,9 @@ MHD_str_pct_decode_in_place_strict_ (char *str)
1958 unsigned char out; 1962 unsigned char out;
1959 if ((0 > h) || (0 > l)) 1963 if ((0 > h) || (0 > l))
1960 return 0; 1964 return 0;
1961 out = (unsigned char) ( (((uint8_t) ((unsigned int) h)) << 4) 1965 out =
1962 | ((uint8_t) ((unsigned int) l)) ); 1966 (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4))
1967 | ((uint8_t) ((unsigned int) l)));
1963 str[w++] = (char) out; 1968 str[w++] = (char) out;
1964 } 1969 }
1965 } 1970 }
@@ -2033,8 +2038,9 @@ MHD_str_pct_decode_in_place_lenient_ (char *str,
2033 str[w++] = d2; 2038 str[w++] = d2;
2034 continue; 2039 continue;
2035 } 2040 }
2036 out = (unsigned char) ( (((uint8_t) ((unsigned int) h)) << 4) 2041 out =
2037 | ((uint8_t) ((unsigned int) l)) ); 2042 (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4))
2043 | ((uint8_t) ((unsigned int) l)));
2038 str[w++] = (char) out; 2044 str[w++] = (char) out;
2039 continue; 2045 continue;
2040 } 2046 }
@@ -2230,11 +2236,11 @@ base64_char_to_value_ (uint8_t c)
2230 if ('Z' >= c) 2236 if ('Z' >= c)
2231 { 2237 {
2232 if ('A' <= c) 2238 if ('A' <= c)
2233 return (MHD_base64_map_type_) (c - 'A') + 0; 2239 return (MHD_base64_map_type_) ((c - 'A') + 0);
2234 if ('0' <= c) 2240 if ('0' <= c)
2235 { 2241 {
2236 if ('9' >= c) 2242 if ('9' >= c)
2237 return (MHD_base64_map_type_) (c - '0') + 52; 2243 return (MHD_base64_map_type_) ((c - '0') + 52);
2238 if ('=' == c) 2244 if ('=' == c)
2239 return -2; 2245 return -2;
2240 return -1; 2246 return -1;
@@ -2246,7 +2252,7 @@ base64_char_to_value_ (uint8_t c)
2246 return -1; 2252 return -1;
2247 } 2253 }
2248 if (('z' >= c) && ('a' <= c)) 2254 if (('z' >= c) && ('a' <= c))
2249 return (MHD_base64_map_type_) (c - 'a') + 26; 2255 return (MHD_base64_map_type_) ((c - 'a') + 26);
2250 return -1; 2256 return -1;
2251} 2257}
2252 2258
@@ -2366,9 +2372,12 @@ MHD_base64_to_bin_n (const char *base64,
2366 const MHD_base64_map_type_ v4 = base64_char_to_value_ (in[i + 3]); 2372 const MHD_base64_map_type_ v4 = base64_char_to_value_ (in[i + 3]);
2367 if ((0 > v1) || (0 > v2) || (0 > v3) || (0 > v4)) 2373 if ((0 > v1) || (0 > v2) || (0 > v3) || (0 > v4))
2368 return 0; 2374 return 0;
2369 out[j + 0] = (uint8_t) ((((uint8_t) v1) << 2) | (((uint8_t) v2) >> 4)); 2375 out[j + 0] = (uint8_t) (((uint8_t) (((uint8_t) v1) << 2))
2370 out[j + 1] = (uint8_t) ((((uint8_t) v2) << 4) | (((uint8_t) v3) >> 2)); 2376 | ((uint8_t) (((uint8_t) v2) >> 4)));
2371 out[j + 2] = (uint8_t) ((((uint8_t) v3) << 6) | (((uint8_t) v4))); 2377 out[j + 1] = (uint8_t) (((uint8_t) (((uint8_t) v2) << 4))
2378 | ((uint8_t) (((uint8_t) v3) >> 2)));
2379 out[j + 2] = (uint8_t) (((uint8_t) (((uint8_t) v3) << 6))
2380 | ((uint8_t) (((uint8_t) v4))));
2372 } 2381 }
2373 j += 3; 2382 j += 3;
2374 } 2383 }
@@ -2385,7 +2394,8 @@ MHD_base64_to_bin_n (const char *base64,
2385 if ((0 > v1) || (0 > v2)) 2394 if ((0 > v1) || (0 > v2))
2386 return 0; /* Invalid char or padding at first two positions */ 2395 return 0; /* Invalid char or padding at first two positions */
2387 mhd_assert (j < bin_size); 2396 mhd_assert (j < bin_size);
2388 out[j++] = (uint8_t) ((((uint8_t) v1) << 2) | (((uint8_t) v2) >> 4)); 2397 out[j++] = (uint8_t) (((uint8_t) (((uint8_t) v1) << 2))
2398 | ((uint8_t) (((uint8_t) v2) >> 4)));
2389 if (0 > v3) 2399 if (0 > v3)
2390 { /* Third char is either padding or invalid */ 2400 { /* Third char is either padding or invalid */
2391 if ((-2 != v3) || (-2 != v4)) 2401 if ((-2 != v3) || (-2 != v4))
@@ -2396,7 +2406,8 @@ MHD_base64_to_bin_n (const char *base64,
2396 } 2406 }
2397 if (j >= bin_size) 2407 if (j >= bin_size)
2398 return 0; /* Not enough space */ 2408 return 0; /* Not enough space */
2399 out[j++] = (uint8_t) ((((uint8_t) v2) << 4) | (((uint8_t) v3) >> 2)); 2409 out[j++] = (uint8_t) (((uint8_t) (((uint8_t) v2) << 4))
2410 | ((uint8_t) (((uint8_t) v3) >> 2)));
2400 if (0 > v4) 2411 if (0 > v4)
2401 { /* Fourth char is either padding or invalid */ 2412 { /* Fourth char is either padding or invalid */
2402 if (-2 != v4) 2413 if (-2 != v4)
@@ -2407,7 +2418,8 @@ MHD_base64_to_bin_n (const char *base64,
2407 } 2418 }
2408 if (j >= bin_size) 2419 if (j >= bin_size)
2409 return 0; /* Not enough space */ 2420 return 0; /* Not enough space */
2410 out[j++] = (uint8_t) ((((uint8_t) v3) << 6) | (((uint8_t) v4))); 2421 out[j++] = (uint8_t) (((uint8_t) (((uint8_t) v3) << 6))
2422 | ((uint8_t) (((uint8_t) v4))));
2411 } 2423 }
2412 return j; 2424 return j;
2413#if MHD_BASE64_FUNC_VERSION >= 2 2425#if MHD_BASE64_FUNC_VERSION >= 2