Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ libshadow_la_SOURCES = \
lockpw.c \
loginprompt.c \
mail.c \
memory/memcpy/memmove.c \
memory/memcpy/memmove.h \
motd.c \
myname.c \
nss.c \
Expand Down Expand Up @@ -223,6 +225,8 @@ libshadow_la_SOURCES = \
string/strcmp/strprefix.h \
string/strcpy/stpecpy.c \
string/strcpy/stpecpy.h \
string/strcpy/strmove.c \
string/strcpy/strmove.h \
string/strcpy/strncat.c \
string/strcpy/strncat.h \
string/strcpy/strncpy.c \
Expand Down
7 changes: 7 additions & 0 deletions lib/memory/memcpy/memmove.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2025-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "memory/memcpy/memmove.h"
26 changes: 26 additions & 0 deletions lib/memory/memcpy/memmove.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2025-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_MEMORY_MEMCPY_MEMMOVE_H_
#define SHADOW_INCLUDE_LIB_MEMORY_MEMCPY_MEMMOVE_H_


#include "config.h"

#include <memory.h>

#include "sizeof.h"


// memmove_T - memory move type-safe
#define memmove_T(dst, src, n, T) memmove_T_(dst, src, n, typeas(T))
#define memmove_T_(dst, src, n, T) do \
{ \
_Generic(dst, T *: (void)0); \
_Generic(src, T *: (void)0); \
memmove(dst, src, (n) * sizeof(T)); \
} while (0)


#endif // include guard
7 changes: 7 additions & 0 deletions lib/string/README
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ strcpy/ - String copying
Do NOT use. I'll remove it soon.

s/
strmove()
Like memmove(3), for strings. It takes the length of the string
internally with strlen(3).

strtcpy()
Copy from a string into another string with truncation.
This is what the Linux kernel calls strscpy().
Expand All @@ -208,6 +212,9 @@ strcpy/ - String copying
MEMCPY()
Like memcpy(3), but takes two arrays.

memmove_T()
Like memmove(3), but type safe.

sprintf/ - Formatted string creation

aprintf(3)
Expand Down
10 changes: 10 additions & 0 deletions lib/string/strcpy/strmove.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2025-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "string/strcpy/strmove.h"


extern inline void strmove(char *dst, char *src);
29 changes: 29 additions & 0 deletions lib/string/strcpy/strmove.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2025-2026, Alejandro Colomar <alx@kernel.org>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_STRCPY_STRMOVE_H_
#define SHADOW_INCLUDE_LIB_STRING_STRCPY_STRMOVE_H_


#include "config.h"

#include <string.h>

#include "attr.h"
#include "memory/memcpy/memmove.h"


ATTR_STRING(2)
inline void strmove(char *dst, char *src);


// strmove - string move
inline void
strmove(char *dst, char *src)
{
memmove_T(dst, src, strlen(src) + 1, char);
}


#endif // include guard
3 changes: 2 additions & 1 deletion src/usermod.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "string/sprintf/aprintf.h"
#include "string/strcmp/streq.h"
#include "string/strcmp/strprefix.h"
#include "string/strcpy/strmove.h"
#include "string/strdup/strdup.h"
#include "string/strspn/stprspn.h"
#include "sysconf.h"
Expand Down Expand Up @@ -489,7 +490,7 @@ new_pw_passwd(char *pw_pass, bool process_selinux)
"updating-password", user_newname, user_newid, 1);
#endif
SYSLOG(LOG_INFO, "unlock user '%s' password", user_newname);
memmove(pw_pass, pw_pass + 1, strlen(pw_pass));
strmove(pw_pass, pw_pass + 1);
} else if (pflg) {
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK,
Expand Down
Loading