kexec-tools: Fix conversion overflow when compiling on 32-bit platforms
Subsystems (2)
PATCH 1/1 kexec-tools: Fix conversion overflow when compiling on 32-bit platforms
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'
805 | *phys_off = UINT64_MAX;
| ^~~~~~~~~~Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.
util_lib/elf_info.c +1 -1
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret; - *phys_off =UINT64_MAX ; + *phys_off = (unsigned long )UINT64_MAX ; ret =read_elf (fd);if (!ret) {
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 18 lines · Helge Deller
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'805 | *phys_off = UINT64_MAX; | ^~~~~~~~~~Fix it by casting
UINT64_MAXto (unsigned long) before storing it to*phys_off.Signed-off-by Helge Deller <[email protected]>util_lib/elf_info.c +0
-0
util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805
Quoted 5 lines
util_lib/elf_info.c +1
-1@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret; - *phys_off =UINT64_MAX ; + *phys_off = (unsigned long )UINT64_MAX ;
This seems to mask the problem that UINT64_MAX is not the right initialiser for unsigned long values on 32-bit platforms.
Could we consider using UINT64_MAX from limits.h instead?
util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
Quoted 4 lines
util_lib/elf_info.c +0
-0ret =read_elf (fd);if (!ret) {
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 22 lines · Simon Horman
Quoted 21 lines · Helge Deller
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'805 | *phys_off = UINT64_MAX; | ^~~~~~~~~~Fix it by casting
UINT64_MAXto (unsigned long) before storing it to*phys_off.Signed-off-by Helge Deller <[email protected]>util_lib/elf_info.c +0
-0@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret;
Quoted 6 lines
util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805
Quoted 2 lines
util_lib/elf_info.c +1
-1- *phys_off =UINT64_MAX ; + *phys_off = (unsigned long )UINT64_MAX ;This seems to mask the problem that
UINT64_MAXis not the right initialiser for unsigned long values on 32-bit platforms. Could we consider usingUINT64_MAXfromlimits.hinstead?
UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigning UINT32_MAX on a 32bit platform might be wrong. So I think the cast above is probably the best solution.
Helge
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 30 lines · Helge Deller
Quoted 22 lines · Simon Horman
Quoted 21 lines · Helge Deller
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'805 | *phys_off = UINT64_MAX; | ^~~~~~~~~~Fix it by casting
UINT64_MAXto (unsigned long) before storing it to*phys_off.Signed-off-by Helge Deller <[email protected]>util_lib/elf_info.c +0
-0@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret;Quoted 6 lines
util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805
Quoted 2 lines
util_lib/elf_info.c +1
-1- *phys_off =UINT64_MAX ; + *phys_off = (unsigned long )UINT64_MAX ;This seems to mask the problem that
UINT64_MAXis not the right initialiser for unsigned long values on 32-bit platforms. Could we consider usingUINT64_MAXfromlimits.hinstead?
Quoted 4 lines
UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigningUINT32_MAXon a 32bit platform might be wrong. So I think the cast above is probably the best solution.
Sorry, I made a typo above.
What I meant is, can we consider using ULONG_MAX.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 31 lines · Simon Horman
Quoted 30 lines · Helge Deller
Quoted 28 lines · Simon Horman
Quoted 18 lines · Helge Deller
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'805 | *phys_off = UINT64_MAX; | ^~~~~~~~~~Fix it by casting
UINT64_MAXto (unsigned long) before storing it to*phys_off.Signed-off-by Helge Deller <[email protected]>util_lib/elf_info.c +0
-0util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805
Quoted 5 lines
util_lib/elf_info.c +1
-1@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret; - *phys_off =UINT64_MAX ; + *phys_off = (unsigned long )UINT64_MAX ;This seems to mask the problem that
UINT64_MAXis not the right initialiser for unsigned long values on 32-bit platforms. Could we consider usingUINT64_MAXfromlimits.hinstead?
Quoted 7 lines
Quoted 4 lines
UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigningUINT32_MAXon a 32bit platform might be wrong. So I think the cast above is probably the best solution.Sorry, I made a typo above.
What I meant is, can we consider usingULONG_MAX.
Yes, that's probably ok.
Helge
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 37 lines · Helge Deller
Quoted 36 lines · Simon Horman
Quoted 34 lines · Helge Deller
Quoted 22 lines · Simon Horman
Quoted 21 lines · Helge Deller
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'805 | *phys_off = UINT64_MAX; | ^~~~~~~~~~Fix it by casting
UINT64_MAXto (unsigned long) before storing it to*phys_off.Signed-off-by Helge Deller <[email protected]>util_lib/elf_info.c +0
-0@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret;Quoted 6 lines
util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805
Quoted 2 lines
util_lib/elf_info.c +1
-1- *phys_off =UINT64_MAX ; + *phys_off = (unsigned long )UINT64_MAX ;This seems to mask the problem that
UINT64_MAXis not the right initialiser for unsigned long values on 32-bit platforms. Could we consider usingUINT64_MAXfromlimits.hinstead?UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigningUINT32_MAXon a 32bit platform might be wrong. So I think the cast above is probably the best solution.
Quoted 4 lines
Quoted 2 lines
Sorry, I made a typo above.
What I meant is, can we consider usingULONG_MAX.Yes, that's probably ok.
Thanks. Will you send an updated patch?
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to
'long unsigned int' changes value from '18446744073709551615' to '4294967295'
805 | *phys_off = UINT64_MAX;
Fix it by using ULONG_MAX instead of UINT64_MAX.
util_lib/elf_info.c +1 -1
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) {int ret; - *phys_off =UINT64_MAX ; + *phys_off =ULONG_MAX ; ret =read_elf (fd);if (!ret) {
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
AppliedQuoted 4 lines · Helge Deller
When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:
Quoted 8 lines
elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to'long unsigned int' changes value from '18446744073709551615' to '4294967295'805 |
*phys_off=UINT64_MAX;Fix it by using
ULONG_MAXinstead ofUINT64_MAX.Signed-off-by Helge Deller <[email protected]>
Thanks, applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec