From 32a244b0ced6ef35149bee25ede7b520c9f48903 Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Mon, 17 Feb 2025 19:10:43 +0100 Subject: [PATCH] Import upstream patch to fix chfn (#1096187) https://github.com/shadow-maint/shadow/pull/1212 --- ...src-Use-strsep-3-instead-of-its-patt.patch | 52 -------------- debian/patches/series | 5 +- ...variable-to-refer-to-the-separated-f.patch | 37 ++++++++++ ...revert-lib-src-Use-strsep-3-instead-.patch | 67 +++++++++++++++++++ ....c-Use-stpsep-instead-of-its-pattern.patch | 33 +++++++++ ...n.c-copy_field-Rename-local-variable.patch | 47 +++++++++++++ 6 files changed, 188 insertions(+), 53 deletions(-) delete mode 100644 debian/patches/Partially-revert-lib-src-Use-strsep-3-instead-of-its-patt.patch create mode 100644 debian/patches/upstream/src-chfn.c-Add-local-variable-to-refer-to-the-separated-f.patch create mode 100644 debian/patches/upstream/src-chfn.c-Partially-revert-lib-src-Use-strsep-3-instead-.patch create mode 100644 debian/patches/upstream/src-chfn.c-Use-stpsep-instead-of-its-pattern.patch create mode 100644 debian/patches/upstream/src-chfn.c-copy_field-Rename-local-variable.patch diff --git a/debian/patches/Partially-revert-lib-src-Use-strsep-3-instead-of-its-patt.patch b/debian/patches/Partially-revert-lib-src-Use-strsep-3-instead-of-its-patt.patch deleted file mode 100644 index 2fc8b7c6..00000000 --- a/debian/patches/Partially-revert-lib-src-Use-strsep-3-instead-of-its-patt.patch +++ /dev/null @@ -1,52 +0,0 @@ -From: Chris Hofstaedtler -Date: Mon, 17 Feb 2025 12:26:07 +0100 -Subject: Partially revert "lib/, src/: Use strsep(3) instead of its pattern" - -This reverts src/chfn.c from commit 16cb664865541162c504a6f5ef5ca4b38b5e0c9a. ---- - src/chfn.c | 17 +++++++++++------ - 1 file changed, 11 insertions(+), 6 deletions(-) - -diff --git a/src/chfn.c b/src/chfn.c -index 4c96fba..f06cb44 100644 ---- a/src/chfn.c -+++ b/src/chfn.c -@@ -216,27 +216,32 @@ static void new_fields (void) - */ - static char *copy_field (char *in, char *out, char *extra) - { -- while (NULL != in) { -- char *f; -+ char *cp = NULL; - -- f = strsep(&in, ","); -+ while (NULL != in) { -+ cp = strchr (in, ','); -+ if (NULL != cp) { -+ *cp++ = '\0'; -+ } - -- if (strchr(f, '=') == NULL) -+ if (strchr (in, '=') == NULL) { - break; -+ } - - if (NULL != extra) { - if (!streq(extra, "")) { - strcat (extra, ","); - } - -- strcat(extra, f); -+ strcat (extra, in); - } -+ in = cp; - } - if ((NULL != in) && (NULL != out)) { - strcpy (out, in); - } - -- return in; -+ return cp; - } - - /* diff --git a/debian/patches/series b/debian/patches/series index 0164cd4a..a24f01a2 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -10,5 +10,8 @@ upstream/a015e919834c90b99947829c6c823f7fe93a8097-E_BAD_NAME.patch upstream/man-useradd.8.xml-Document-new-exit-code-19-E_BAD_NAME.patch upstream/Revert-lib-src-Use-local-time-for-human-readable-dates.patch Revert-lib-strtoday.c-strtoday-Fix-calculation.patch -Partially-revert-lib-src-Use-strsep-3-instead-of-its-patt.patch Warn-when-badname-and-variants-are-given.patch +upstream/src-chfn.c-Partially-revert-lib-src-Use-strsep-3-instead-.patch +upstream/src-chfn.c-Use-stpsep-instead-of-its-pattern.patch +upstream/src-chfn.c-Add-local-variable-to-refer-to-the-separated-f.patch +upstream/src-chfn.c-copy_field-Rename-local-variable.patch diff --git a/debian/patches/upstream/src-chfn.c-Add-local-variable-to-refer-to-the-separated-f.patch b/debian/patches/upstream/src-chfn.c-Add-local-variable-to-refer-to-the-separated-f.patch new file mode 100644 index 00000000..c32f780a --- /dev/null +++ b/debian/patches/upstream/src-chfn.c-Add-local-variable-to-refer-to-the-separated-f.patch @@ -0,0 +1,37 @@ +From: Alejandro Colomar +Date: Mon, 17 Feb 2025 13:44:55 +0100 +Subject: src/chfn.c: Add local variable to refer to the separated field + +Signed-off-by: Alejandro Colomar +--- + src/chfn.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/src/chfn.c b/src/chfn.c +index 1799d6b..3fc94dc 100644 +--- a/src/chfn.c ++++ b/src/chfn.c +@@ -220,18 +220,20 @@ static char *copy_field (char *in, char *out, char *extra) + char *cp = NULL; + + while (NULL != in) { ++ const char *f; ++ ++ f = in; + cp = stpsep(in, ","); + +- if (strchr (in, '=') == NULL) { ++ if (strchr(f, '=') == NULL) + break; +- } + + if (NULL != extra) { + if (!streq(extra, "")) { + strcat (extra, ","); + } + +- strcat (extra, in); ++ strcat(extra, f); + } + in = cp; + } diff --git a/debian/patches/upstream/src-chfn.c-Partially-revert-lib-src-Use-strsep-3-instead-.patch b/debian/patches/upstream/src-chfn.c-Partially-revert-lib-src-Use-strsep-3-instead-.patch new file mode 100644 index 00000000..f0213316 --- /dev/null +++ b/debian/patches/upstream/src-chfn.c-Partially-revert-lib-src-Use-strsep-3-instead-.patch @@ -0,0 +1,67 @@ +From: Alejandro Colomar +Date: Mon, 17 Feb 2025 13:23:37 +0100 +Subject: src/chfn.c: Partially revert "lib/, + src/: Use strsep(3) instead of its pattern" + +This partially reverts commit 16cb664865541162c504a6f5ef5ca4b38b5e0c9a. + +I'll try to reintroduce this change more carefully. +For now, let's revert to a known-good state. + +The problem was due to accidentally ignoring the effects of the 'break' +on the 'cp' variable. + +Fixes: 16cb66486554 (2024-07-01; "lib/, src/: Use strsep(3) instead of its pattern") +Closes: +Link: +Link: +Reported-by: Chris Hofstaedtler +Suggested-by: Chris Hofstaedtler +Signed-off-by: Alejandro Colomar +--- + src/chfn.c | 17 +++++++++++------ + 1 file changed, 11 insertions(+), 6 deletions(-) + +diff --git a/src/chfn.c b/src/chfn.c +index 4c96fba..f06cb44 100644 +--- a/src/chfn.c ++++ b/src/chfn.c +@@ -216,27 +216,32 @@ static void new_fields (void) + */ + static char *copy_field (char *in, char *out, char *extra) + { +- while (NULL != in) { +- char *f; ++ char *cp = NULL; + +- f = strsep(&in, ","); ++ while (NULL != in) { ++ cp = strchr (in, ','); ++ if (NULL != cp) { ++ *cp++ = '\0'; ++ } + +- if (strchr(f, '=') == NULL) ++ if (strchr (in, '=') == NULL) { + break; ++ } + + if (NULL != extra) { + if (!streq(extra, "")) { + strcat (extra, ","); + } + +- strcat(extra, f); ++ strcat (extra, in); + } ++ in = cp; + } + if ((NULL != in) && (NULL != out)) { + strcpy (out, in); + } + +- return in; ++ return cp; + } + + /* diff --git a/debian/patches/upstream/src-chfn.c-Use-stpsep-instead-of-its-pattern.patch b/debian/patches/upstream/src-chfn.c-Use-stpsep-instead-of-its-pattern.patch new file mode 100644 index 00000000..b0643448 --- /dev/null +++ b/debian/patches/upstream/src-chfn.c-Use-stpsep-instead-of-its-pattern.patch @@ -0,0 +1,33 @@ +From: Alejandro Colomar +Date: Mon, 17 Feb 2025 13:40:02 +0100 +Subject: src/chfn.c: Use stpsep() instead of its pattern + +Signed-off-by: Alejandro Colomar +--- + src/chfn.c | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/src/chfn.c b/src/chfn.c +index f06cb44..1799d6b 100644 +--- a/src/chfn.c ++++ b/src/chfn.c +@@ -36,6 +36,7 @@ + #include "string/strcmp/streq.h" + #include "string/strcpy/strtcpy.h" + #include "string/strdup/xstrdup.h" ++#include "string/strtok/stpsep.h" + + + /* +@@ -219,10 +220,7 @@ static char *copy_field (char *in, char *out, char *extra) + char *cp = NULL; + + while (NULL != in) { +- cp = strchr (in, ','); +- if (NULL != cp) { +- *cp++ = '\0'; +- } ++ cp = stpsep(in, ","); + + if (strchr (in, '=') == NULL) { + break; diff --git a/debian/patches/upstream/src-chfn.c-copy_field-Rename-local-variable.patch b/debian/patches/upstream/src-chfn.c-copy_field-Rename-local-variable.patch new file mode 100644 index 00000000..e550a11c --- /dev/null +++ b/debian/patches/upstream/src-chfn.c-copy_field-Rename-local-variable.patch @@ -0,0 +1,47 @@ +From: Alejandro Colomar +Date: Mon, 17 Feb 2025 15:33:46 +0100 +Subject: src/chfn.c: copy_field(): Rename local variable + +This makes it more obvious what that pointer is. + +Signed-off-by: Alejandro Colomar +--- + src/chfn.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/chfn.c b/src/chfn.c +index 3fc94dc..d62bb8a 100644 +--- a/src/chfn.c ++++ b/src/chfn.c +@@ -217,13 +217,13 @@ static void new_fields (void) + */ + static char *copy_field (char *in, char *out, char *extra) + { +- char *cp = NULL; ++ char *next = NULL; + + while (NULL != in) { + const char *f; + + f = in; +- cp = stpsep(in, ","); ++ next = stpsep(in, ","); + + if (strchr(f, '=') == NULL) + break; +@@ -235,13 +235,13 @@ static char *copy_field (char *in, char *out, char *extra) + + strcat(extra, f); + } +- in = cp; ++ in = next; + } + if ((NULL != in) && (NULL != out)) { + strcpy (out, in); + } + +- return cp; ++ return next; + } + + /*