Message ID | 20170503211119.13743-1-xypron.glpk@gmx.de |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
On Thu, May 4, 2017 at 2:41 AM, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote: > If endptr is NULL we should not dereference it. > > The problem was indicated by cppcheck. > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > tools/sunxi-spl-image-builder.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/sunxi-spl-image-builder.c b/tools/sunxi-spl-image-builder.c > index d538a38813..0072a64728 100644 > --- a/tools/sunxi-spl-image-builder.c > +++ b/tools/sunxi-spl-image-builder.c > @@ -433,7 +433,7 @@ int main(int argc, char **argv) > break; > case 'c': > info.ecc_strength = strtol(optarg, &endptr, 0); > - if (endptr || *endptr == '/') > + if (endptr && *endptr == '/') Did the config function as 'if' with single argument, can you check below sample - couldn't reproduce null dereference. # cppcheck --library=test.cfg tools/sunxi-spl-image-builder.c Checking tools/sunxi-spl-image-builder.c... [tools/sunxi-spl-image-builder.c:286]: (error) Resource leak: src [tools/sunxi-spl-image-builder.c:286]: (error) Resource leak: dst [tools/sunxi-spl-image-builder.c:286]: (error) Resource leak: rnd [tools/sunxi-spl-image-builder.c:263]: (error) Memory leak: buffer # cat test.cfg <?xml version="1.0"?> <def> <function name="if"> <arg nr="1"> <not-null/> </arg> </function> </def> thanks!
diff --git a/tools/sunxi-spl-image-builder.c b/tools/sunxi-spl-image-builder.c index d538a38813..0072a64728 100644 --- a/tools/sunxi-spl-image-builder.c +++ b/tools/sunxi-spl-image-builder.c @@ -433,7 +433,7 @@ int main(int argc, char **argv) break; case 'c': info.ecc_strength = strtol(optarg, &endptr, 0); - if (endptr || *endptr == '/') + if (endptr && *endptr == '/') info.ecc_step_size = strtol(endptr + 1, NULL, 0); break; case 'p':
If endptr is NULL we should not dereference it. The problem was indicated by cppcheck. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> --- tools/sunxi-spl-image-builder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)