env export fixes
cover env export fixes
These patches fix two issues in the export of environment variables with CRC calculation.
Pierre Aubert (2):
hashtable: fix the export lenght computation.
env export fix: compute the CRC on the real lenght of the exported
variables.
common/cmd_nvedit.c | 5 +++-- lib/hashtable.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.6.5
PATCH 1/2 hashtable: fix the export lenght computation.
The room for the '=' and the sep char was reserved twice.
--- lib/hashtable.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/hashtable.c +1 -1
@@ -623,7 +623,7 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag, list[n++] = ep; - totlen +=strlen (ep->key) +2 ; + totlen +=strlen (ep->key);if (sep =='\0' ) { totlen +=strlen (ep->data);
Signature · 1 line
1.7.6.5
PATCH 1/2 hashtable: fix the export lenght computation.
Dear Pierre Aubert,
Quoted 1 line · In message <[email protected]> you wrote:
The room for the '=' and the sep char was reserved twice.
Are you sure? Keep in mind that the termination of the list is a _double_ NUL byte. IIRC this is what we do here.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de When properly administered, vacations do not diminish productivity: for every week you're away and get nothing done, there's another when your boss is away and you get twice as much done. -- Daniel B. Luten
PATCH 1/2 hashtable: fix the export lenght computation.
Dear Wolfgang Denk,
Le 14/11/2013 18:25, Wolfgang Denk a ?crit :
Quoted 6 lines
Dear Pierre Aubert,
Quoted 1 line · In message <[email protected]> you wrote:
The room for the '=' and the sep char was reserved twice.
Are you sure? Keep in mind that the termination of the list is a _double_ NUL byte. IIRC this is what we do here.
Yes, I'm sure. The termination of the list (last NULL after the last separator) is added at line 666
Quoted 1 line
666 size = totlen + 1;
In the actual code, the lenght is two large of 2 char for each exported variable.
Best regards
Quoted 5 lines
Best regards,
Wolfgang Denk
PATCH 2/2 env export fix: compute the CRC on the real lenght of the exported variables.
In reply to Pierre Aubert--- common/cmd_nvedit.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
common/cmd_nvedit.c +3 -2
@@ -922,14 +922,15 @@ NXTARG: ; len =hexport_r (&env_htab,'\0' ,H_MATCH_KEY |H_MATCH_IDENT , - &res,ENV_SIZE , argc, argv); + &res, size, argc, argv); +if (len <0 ) {error ("Cannot export environment: errno = %d\n" , errno);return 1 ; }if (chk) { - envp->crc =crc32 (0 , envp->data,ENV_SIZE ); + envp->crc =crc32 (0 , envp->data, len);#ifdef CONFIG_ENV_ADDR_REDUND envp->flags =ACTIVE_FLAG ;#endif
Signature · 1 line
1.7.6.5
PATCH 2/2 env export fix: compute the CRC on the real lenght of the exported variables.
Dear Pierre Aubert,
Quoted 14 lines · In message <[email protected]> you wrote:
Signed-off-by Pierre Aubert <[email protected]>--- common/cmd_nvedit.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)common/cmd_nvedit.c +0
-1@@ -922,14 +922,15 @@ NXTARG: ; len = hexport_r(&env_htab, '\0', H_MATCH_KEY | H_MATCH_IDENT, - &res,ENV_SIZE , argc, argv);
common/cmd_nvedit.c NXTARG: ; · line 933
Quoted 10 lines
common/cmd_nvedit.c +3
-1+ &res, size, argc, argv); +if (len <0 ) {error ("Cannot export environment: errno = %d\n" , errno);return 1 ; }if (chk) { - envp->crc =crc32 (0 , envp->data,ENV_SIZE ); + envp->crc =crc32 (0 , envp->data, len);
This is not correct. When exporting with CRC, then the CRC computation should be the same as is done with the persistently stored environment, i. e. it should be taken over ENV_SIZE bytes.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Hindsight is an exact science.
PATCH 2/2 env export fix: compute the CRC on the real lenght of the exported variables.
Dear Wolfgang Denk,
Le 14/11/2013 18:24, Wolfgang Denk a ?crit :
Quoted 24 lines
Dear Pierre Aubert,
Quoted 21 lines · In message <[email protected]> you wrote:
Signed-off-by Pierre Aubert <[email protected]>--- common/cmd_nvedit.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)common/cmd_nvedit.c +2
-1@@ -922,14 +922,15 @@ NXTARG: ; len =hexport_r (&env_htab,'\0' ,H_MATCH_KEY |H_MATCH_IDENT , - &res,ENV_SIZE , argc, argv); + &res, size, argc, argv); +if (len <0 ) {error ("Cannot export environment: errno = %d\n" , errno);return 1 ; }
Quoted 6 lines
common/cmd_nvedit.c NXTARG: ; · line 933
Quoted 3 lines
common/cmd_nvedit.c +1
-1if (chk) { - envp->crc =crc32 (0 , envp->data,ENV_SIZE ); + envp->crc =crc32 (0 , envp->data, len);This is not correct. When exporting with CRC, then the CRC computation should be the same as is done with the persistently stored environment, i. e. it should be taken over
ENV_SIZEbytes.
In this case, there's an inconstisency between the export and the import. It isn't possible to export some variables and the reimport them:
U-Boot > env export -c <addr>
U-Boot > env import -c <same addr> fails with a CRC error.
The import computes the CRC on the real lenght of the environment variables. IMO, as the import and the export are done to work together, it seems to me that the export should compute its CRC on the real lenght.
Best regards
Quoted 5 lines
Best regards,
Wolfgang Denk
PATCH 2/2 env export fix: compute the CRC on the real lenght of the exported variables.
[ Catching up on some old emails ]
Quoted 31 lines · Pierre AUBERT
Dear Wolfgang Denk,
Le 14/11/2013 18:24, Wolfgang Denk a ?crit :
Quoted 20 lines
Dear Pierre Aubert,
Quoted 17 lines · In message <[email protected]> you wrote:
Signed-off-by Pierre Aubert <[email protected]>--- common/cmd_nvedit.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)common/cmd_nvedit.c +2
-1@@ -922,14 +922,15 @@ NXTARG: ; len =hexport_r (&env_htab,'\0' ,H_MATCH_KEY |H_MATCH_IDENT , - &res,ENV_SIZE , argc, argv); + &res, size, argc, argv); +if (len <0 ) {error ("Cannot export environment: errno = %d\n" , errno);Quoted 8 lines
common/cmd_nvedit.c NXTARG: ; · line 933
Quoted 5 lines
common/cmd_nvedit.c +1
-1return 1 ; }if (chk) { - envp->crc =crc32 (0 , envp->data,ENV_SIZE ); + envp->crc =crc32 (0 , envp->data, len);This is not correct. When exporting with CRC, then the CRC computation should be the same as is done with the persistently stored environment, i. e. it should be taken over
ENV_SIZEbytes.
Quoted 9 lines
In this case, there's an inconstisency between the export and the import. It isn't possible to export some variables and the reimport them:
U-Boot > env export -c <addr>
U-Boot > env import -c <same addr> fails with a CRC error. The import computes the CRC on the real lenght of the environment variables. IMO, as the import and the export are done to work together, it seems to me that the export should compute its CRC on the real lenght.
But env import -c <same addr> $filesize does work as the export sets filesize.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140226/4f4673e6/attachment.pgp>
PATCH 2/2 env export fix: compute the CRC on the real lenght of the exported variables.
Dear Tom Rini
Le 26/02/2014 21:02, Tom Rini a ?crit :
Quoted 43 lines
[ Catching up on some old emails ]
Quoted 31 lines · Pierre AUBERT
Dear Wolfgang Denk,
Le 14/11/2013 18:24, Wolfgang Denk a ?crit :
Quoted 20 lines
Dear Pierre Aubert,
Quoted 17 lines · In message <[email protected]> you wrote:
Signed-off-by Pierre Aubert <[email protected]>--- common/cmd_nvedit.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)common/cmd_nvedit.c +2
-1@@ -922,14 +922,15 @@ NXTARG: ; len =hexport_r (&env_htab,'\0' ,H_MATCH_KEY |H_MATCH_IDENT , - &res,ENV_SIZE , argc, argv); + &res, size, argc, argv); +if (len <0 ) {error ("Cannot export environment: errno = %d\n" , errno);Quoted 8 lines
common/cmd_nvedit.c NXTARG: ; · line 933
Quoted 5 lines
common/cmd_nvedit.c +1
-1return 1 ; }if (chk) { - envp->crc =crc32 (0 , envp->data,ENV_SIZE ); + envp->crc =crc32 (0 , envp->data, len);This is not correct. When exporting with CRC, then the CRC computation should be the same as is done with the persistently stored environment, i. e. it should be taken over
ENV_SIZEbytes.Quoted 9 lines
In this case, there's an inconstisency between the export and the import. It isn't possible to export some variables and the reimport them:
U-Boot > env export -c <addr>
U-Boot > env import -c <same addr> fails with a CRC error. The import computes the CRC on the real lenght of the environment variables. IMO, as the import and the export are done to work together, it seems to me that the export should compute its CRC on the real lenght.
Quoted 3 lines
But env import -c <same addr> $filesize does work as the export sets filesize.
You're right, but my purpose wasn't to export and reimport immediatly the same environment.
I thought it was more logical to have the same behaviour between "sister" functions.
Best regards
PATCH 2/2 env export fix: compute the CRC on the real lenght of the exported variables.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 47 lines · Pierre AUBERT
Dear Tom Rini
Le 26/02/2014 21:02, Tom Rini a ?crit :
Quoted 44 lines
[ Catching up on some old emails ]
Quoted 41 lines · Pierre AUBERT
Dear Wolfgang Denk,
Le 14/11/2013 18:24, Wolfgang Denk a ?crit :
Quoted 21 lines
Dear Pierre Aubert,
In message <[email protected]>
Quoted 17 lines · you
Signed-off-by Pierre Aubert <[email protected]>--- common/cmd_nvedit.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)common/cmd_nvedit.c +2
-1@@ -922,14 +922,15 @@ NXTARG: ; len =hexport_r (&env_htab,'\0' ,H_MATCH_KEY |H_MATCH_IDENT , - &res,ENV_SIZE , argc, argv); + &res, size, argc, argv); +if (len <0 ) {error ("Cannot export environment: errno = %d\n" , errno);Quoted 8 lines
common/cmd_nvedit.c NXTARG: ; · line 933
Quoted 5 lines
common/cmd_nvedit.c +1
-1return 1 ; }if (chk) { - envp->crc =crc32 (0 , envp->data,ENV_SIZE ); + envp->crc =crc32 (0 , envp->data, len);This is not correct. When exporting with CRC, then the CRC computation should be the same as is done with the persistently stored environment, i. e. it should be taken over
ENV_SIZEbytes.In this case, there's an inconstisency between the export and the import. It isn't possible to export some variables and the reimport them:
U-Boot > env export -c <addr>
U-Boot > env import -c <same addr> fails with a CRC error. The import computes the CRC on the real lenght of the environment variables. IMO, as the import and the export are done to work together, it seems to me that the export should compute its CRC on the real lenght.
Quoted 8 lines
Quoted 3 lines
But env import -c <same addr> $filesize does work as the export sets filesize.
You're right, but my purpose wasn't to export and reimport immediatly the same environment.
I thought it was more logical to have the same behaviour between "sister" functions.
I see what you mean, yes. I think that we need to make the size parameter to import non-optional as assuming a whole ENV_SIZE chunk would have been imported doesn't make sense.
- --
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJTFLzwAAoJENk4IS6UOR1WM9sP/RriAefiFFrD5GcVURLfD6Ek GDmPWuRg+NFEWHH/Z4eCyvxXaEurLnJcsVF8ZQblWT7zFYu+2weYpLPNYC/zKxzr VDENmOHndPiDRzr5tfkXGiNXYWE46cSVysx5VYznRDH6sDsE+URJxXqZlefBZgw/ 1l0ct5iQUWLmXkRJGQPsj7E4hpedUrBCNavoMh10adLZifWrtty03jN3sOerXhvE qsAbm6ghrvtnC0b9Yj/FcyYFPgw0iG6VhLfCB10U7kwtVK4/Pl+QQNZaaDAPAgkN OkdqiktIa5SyX4l94TBxb2Ixnxe7emZcub1WKrIa3zWNvy744e0bVPmtIVX1vYyT GoaBTG+RcB0fnELt2Uj+odRqQS08KJrSJDOBzIiNzw0VlfSRwaXgK+wTl+3UY0Zt JFiAPeOFGuYndWQJzRf/GKwhaElRV1NjLS1vFN1DHlNLjkv9xF5XJTiED+j7jGYQ UCA26m75KtpAJXBjfE7Y7kyGENP6e9RxwSjwbnJcf0smbpIXi1KyU8bOXyriIK4e oDtprRIxwfL0EdGAlbBNB+RfNxXjB+/lVsVyZyXjmDSeMogYqPIElhRsTMRJzsPx upHUDvSeHqcTW/3nTtkBlnKTRRc+kze+fP3jwSsY06MWwQQxucvLdoqVzPKbQn/E hBWjNm6FMSV0DYbaf1k8
=GS4O
-----END PGP SIGNATURE-----