Closed ac000 closed 4 months ago
$ git range-diff 02da5d35...27e0f22f
1: 02da5d35 ! 1: 27e0f22f Fix check in nxt_conf_json_parse_value()
@@ Metadata
Author: Andrew Clayton <a.clayton@nginx.com>
## Commit message ##
- Fix check in nxt_conf_json_parse_value()
+ Configuration: Fix check in nxt_conf_json_parse_value()
If we compile Unit with -Wstrict-overflow=5 (as we do with clang) then
we get the following warning
@@ Commit message
makes the above calculation come out as 253 (relying on unsigned integer
wraparound) which was probably the intended way for it to work.
+ Reviewed-by: Reviewed-by: Zhidao Hong <z.hong@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
## src/nxt_conf.c ##
Fix copy paste snafu
$ git range-diff 27e0f22f...8ff606fb
1: 27e0f22f ! 1: 8ff606fb Configuration: Fix check in nxt_conf_json_parse_value()
@@ Commit message
makes the above calculation come out as 253 (relying on unsigned integer
wraparound) which was probably the intended way for it to work.
- Reviewed-by: Reviewed-by: Zhidao Hong <z.hong@f5.com>
+ Reviewed-by: Zhidao Hong <z.hong@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
## src/nxt_conf.c ##
If we compile Unit with -Wstrict-overflow=5 (as we do with clang) then we get the following warning
Does this actually cause an issue?... well, yes. Using this minimal test config to show the problem
With the above if () statement that triggers the warning, my assumption here is that we only want a digit now. '0' - '9'.
ch is a u_char, however if ch is any character with an ASCII code < 48 ('0') e.g if ch is '-' (45) then we get 45 - 48 = -3, through arithmetic conversion, which makes the if () statement true (when it shouldn't) then at some point we get the following error returned from the controller
Instead of the expected
Casting the result of (ch - '0') to u_char resolves this issue, this makes the above calculation come out as 253 (relying on unsigned integer wraparound) which was probably the intended way for it to work.