[pacman-dev] FS#66472: correct length of ".files.sig" string

Message ID c6c43409-b0b4-aa1e-a63e-1163b0597b92@0.smtp.remotehost.it
State New
Headers show
Series [pacman-dev] FS#66472: correct length of ".files.sig" string | expand

Commit Message

Pascal Ernster Jan. 20, 2021, 4:37 a.m. UTC
Signed-off-by: Pascal Ernster <pacman-dev@hardfalcon.net>
---
  src/pacman/sync.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Anatol Pomozov Jan. 20, 2021, 6:10 p.m. UTC | #1
Hi

On Tue, Jan 19, 2021 at 8:37 PM Pascal Ernster
<pacman-dev@hardfalcon.net> wrote:
>
>
> Signed-off-by: Pascal Ernster <pacman-dev@hardfalcon.net>
> ---
>   src/pacman/sync.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/pacman/sync.c b/src/pacman/sync.c
> index a05af5da..9ec4c92e 100644
> --- a/src/pacman/sync.c
> +++ b/src/pacman/sync.c
> @@ -105,7 +105,7 @@ static int sync_cleandb(const char *dbpath)
>                         dbname = strndup(dname, len - 7);
>                 } else if(len > 6 && strcmp(dname + len - 6, ".files") == 0) {
>                         dbname = strndup(dname, len - 6);
> -               } else if(len > 6 && strcmp(dname + len - 6, ".files.sig") == 0) {
> +               } else if(len > 10 && strcmp(dname + len - 10, ".files.sig") == 0) {
>                         dbname = strndup(dname, len - 10);
>                 } else {
>                         ret += unlink_verbose(path, 0);

Thank you. The fix looks good.

It would be great to have a bit more verbose commit message, including
description of the user error (i.e. how this error manifests to a
pacman user) and steps to reproduce it.
Eli Schwartz Jan. 20, 2021, 7:03 p.m. UTC | #2
On 1/20/21 1:10 PM, Anatol Pomozov wrote:
> Thank you. The fix looks good.
> 
> It would be great to have a bit more verbose commit message, including
> description of the user error (i.e. how this error manifests to a
> pacman user) and steps to reproduce it.

Added to that; I'd like to see the FS#66472 (ticket reference) moved out 
of the commit title and into the extended description. Preferably on its 
own line as

Fixes FS#66472
Emil Velikov Jan. 20, 2021, 11:10 p.m. UTC | #3
On Wed, 20 Jan 2021 at 04:37, Pascal Ernster <pacman-dev@hardfalcon.net> wrote:
>
>
> Signed-off-by: Pascal Ernster <pacman-dev@hardfalcon.net>
> ---
>   src/pacman/sync.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/pacman/sync.c b/src/pacman/sync.c
> index a05af5da..9ec4c92e 100644
> --- a/src/pacman/sync.c
> +++ b/src/pacman/sync.c
> @@ -105,7 +105,7 @@ static int sync_cleandb(const char *dbpath)
>                         dbname = strndup(dname, len - 7);
>                 } else if(len > 6 && strcmp(dname + len - 6, ".files") == 0) {
>                         dbname = strndup(dname, len - 6);
> -               } else if(len > 6 && strcmp(dname + len - 6, ".files.sig") == 0) {
> +               } else if(len > 10 && strcmp(dname + len - 10, ".files.sig") == 0) {
>                         dbname = strndup(dname, len - 10);
Fwiw one could replace the hard-coded numbers with strlen() which the
compiler will turn into compile time constants.
To make the code a little easier to read, a trivial static inline
helper could be introduced.

I might follow-up at some point unless someone beats me to it :-P

-Emil

Patch

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index a05af5da..9ec4c92e 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -105,7 +105,7 @@  static int sync_cleandb(const char *dbpath)
  			dbname = strndup(dname, len - 7);
  		} else if(len > 6 && strcmp(dname + len - 6, ".files") == 0) {
  			dbname = strndup(dname, len - 6);
-		} else if(len > 6 && strcmp(dname + len - 6, ".files.sig") == 0) {
+		} else if(len > 10 && strcmp(dname + len - 10, ".files.sig") == 0) {
  			dbname = strndup(dname, len - 10);
  		} else {
  			ret += unlink_verbose(path, 0);