From: Alejandro Colomar Date: Mon, 11 Dec 2023 13:01:38 +0000 (+0100) Subject: lib/: Remove incorrect /*@out@*/ comment from functions that read the pointee X-Git-Tag: 4.15.0-rc1~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9ca6b71e76d0e09cada312270b406d10edca84c2;p=thirdparty%2Fshadow.git lib/: Remove incorrect /*@out@*/ comment from functions that read the pointee These functions (e.g., gr_free()), explicitly dereference the pointer and read the pointee. The /@out@/ comment, which is (almost) analogous to the [[gnu::access(write_only, ...)]] attribute, means that the pointee can be uninitialized, since it won't read it. There's a difference between /@out@/ and the GCC attribute: the attribute doesn't require that the call writes to the pointee, while /@out@/ requires that the pointee be fully initialized after the call, so it _must_ write to it. A guess of why it was used is that these functions are similar to free(3), which does not read the memory it frees, and so one would assume that if it doesn't read, write_only (or equivalents) are good. That's wrong in several ways: - free(3) does not read _nor_ write to the memory, so it would be slightly inappropriate to use write_only with it. It wouldn't be "wrong", but [[gnu::access(none, ...)]] would be more appropriate. - Because /@out@/ requires that the call writes to the pointee, it would be wrong to use it in free(3), which doesn't write to the pointee. - Our functions are similar to free(3) conceptually, but they don't behave like free(3), since they do read the memory (pointee) (and also write to it), and thus they're actually read_write. Link: Cc: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/commonio.h b/lib/commonio.h index d5354bfbe..7ea82d45e 100644 --- a/lib/commonio.h +++ b/lib/commonio.h @@ -37,7 +37,7 @@ struct commonio_ops { /* * free() the object including any strings pointed by it. */ - void (*free) (/*@out@*/ /*@only@*/void *); + void (*free)(/*@only@*/void *); /* * Return the name of the object (for example, pw_name diff --git a/lib/groupio.c b/lib/groupio.c index d9d9823bb..7b9d45f2c 100644 --- a/lib/groupio.c +++ b/lib/groupio.c @@ -36,7 +36,8 @@ static /*@null@*/ /*@only@*/void *group_dup (const void *ent) return __gr_dup (gr); } -static void group_free (/*@out@*/ /*@only@*/void *ent) +static void +group_free(/*@only@*/void *ent) { struct group *gr = ent; diff --git a/lib/groupmem.c b/lib/groupmem.c index eb3348aa5..69d4435be 100644 --- a/lib/groupmem.c +++ b/lib/groupmem.c @@ -77,7 +77,8 @@ void gr_free_members (struct group *grent) } } -void gr_free (/*@out@*/ /*@only@*/struct group *grent) +void +gr_free(/*@only@*/struct group *grent) { free (grent->gr_name); if (NULL != grent->gr_passwd) { diff --git a/lib/prototypes.h b/lib/prototypes.h index 756bcdd66..804ad96fe 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -188,7 +188,7 @@ extern void __gr_set_changed (void); /* groupmem.c */ extern /*@null@*/ /*@only@*/struct group *__gr_dup (const struct group *grent); extern void gr_free_members (struct group *grent); -extern void gr_free (/*@out@*/ /*@only@*/struct group *grent); +extern void gr_free(/*@only@*/struct group *grent); /* hushed.c */ extern bool hushed (const char *username); @@ -355,7 +355,7 @@ extern /*@dependent@*/ /*@null@*/struct commonio_entry *__pw_get_head (void); /* pwmem.c */ extern /*@null@*/ /*@only@*/struct passwd *__pw_dup (const struct passwd *pwent); -extern void pw_free (/*@out@*/ /*@only@*/struct passwd *pwent); +extern void pw_free(/*@only@*/struct passwd *pwent); /* csrand.c */ unsigned long csrand (void); @@ -418,7 +418,7 @@ extern struct spwd *sgetspent (const char *string); /* sgroupio.c */ extern void __sgr_del_entry (const struct commonio_entry *ent); extern /*@null@*/ /*@only@*/struct sgrp *__sgr_dup (const struct sgrp *sgent); -extern void sgr_free (/*@out@*/ /*@only@*/struct sgrp *sgent); +extern void sgr_free(/*@only@*/struct sgrp *sgent); extern /*@dependent@*/ /*@null@*/struct commonio_entry *__sgr_get_head (void); extern void __sgr_set_changed (void); @@ -428,7 +428,7 @@ extern void __spw_del_entry (const struct commonio_entry *ent); /* shadowmem.c */ extern /*@null@*/ /*@only@*/struct spwd *__spw_dup (const struct spwd *spent); -extern void spw_free (/*@out@*/ /*@only@*/struct spwd *spent); +extern void spw_free(/*@only@*/struct spwd *spent); /* shell.c */ extern int shell (const char *file, /*@null@*/const char *arg, char *const envp[]); diff --git a/lib/pwio.c b/lib/pwio.c index 95ed0abcc..3497c7545 100644 --- a/lib/pwio.c +++ b/lib/pwio.c @@ -26,7 +26,8 @@ static /*@null@*/ /*@only@*/void *passwd_dup (const void *ent) return __pw_dup (pw); } -static void passwd_free (/*@out@*/ /*@only@*/void *ent) +static void +passwd_free(/*@only@*/void *ent) { struct passwd *pw = ent; diff --git a/lib/pwmem.c b/lib/pwmem.c index 3d868a850..9c6e58d7e 100644 --- a/lib/pwmem.c +++ b/lib/pwmem.c @@ -70,7 +70,8 @@ return pw; } -void pw_free (/*@out@*/ /*@only@*/struct passwd *pwent) +void +pw_free(/*@only@*/struct passwd *pwent) { if (pwent != NULL) { free (pwent->pw_name); diff --git a/lib/sgroupio.c b/lib/sgroupio.c index cbbdff788..0297df4ae 100644 --- a/lib/sgroupio.c +++ b/lib/sgroupio.c @@ -117,14 +117,16 @@ static /*@null@*/ /*@only@*/void *gshadow_dup (const void *ent) return __sgr_dup (sg); } -static void gshadow_free (/*@out@*/ /*@only@*/void *ent) +static void +gshadow_free(/*@only@*/void *ent) { struct sgrp *sg = ent; sgr_free (sg); } -void sgr_free (/*@out@*/ /*@only@*/struct sgrp *sgent) +void +sgr_free(/*@only@*/struct sgrp *sgent) { size_t i; free (sgent->sg_name); diff --git a/lib/shadowio.c b/lib/shadowio.c index 494ef7c8a..d2c3b4730 100644 --- a/lib/shadowio.c +++ b/lib/shadowio.c @@ -31,7 +31,8 @@ static /*@null@*/ /*@only@*/void *shadow_dup (const void *ent) return __spw_dup (sp); } -static void shadow_free (/*@out@*//*@only@*/void *ent) +static void +shadow_free(/*@only@*/void *ent) { struct spwd *sp = ent; diff --git a/lib/shadowmem.c b/lib/shadowmem.c index c3c7c4cc3..9d8f193b2 100644 --- a/lib/shadowmem.c +++ b/lib/shadowmem.c @@ -56,7 +56,8 @@ return sp; } -void spw_free (/*@out@*/ /*@only@*/struct spwd *spent) +void +spw_free(/*@only@*/struct spwd *spent) { if (spent != NULL) { free (spent->sp_namp); diff --git a/lib/subordinateio.c b/lib/subordinateio.c index d67d56c91..844de5f06 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -56,7 +56,8 @@ static /*@null@*/ /*@only@*/void *subordinate_dup (const void *ent) * * @ent: pointer to a subordinate_range struct to free. */ -static void subordinate_free (/*@out@*/ /*@only@*/void *ent) +static void +subordinate_free(/*@only@*/void *ent) { struct subordinate_range *rangeent = ent;