From: Ian Jackson Date: Sun, 21 Aug 2022 13:57:48 +0000 (+0100) Subject: prefork-interp: include more stuff in hash X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=08987e35b10d505f8f54102190cf5c0a87cb2093;p=chiark-utils.git prefork-interp: include more stuff in hash Signed-off-by: Ian Jackson --- diff --git a/cprogs/prefork-interp.c b/cprogs/prefork-interp.c index 47ad361..8fcb5dc 100644 --- a/cprogs/prefork-interp.c +++ b/cprogs/prefork-interp.c @@ -363,6 +363,7 @@ */ #include +#include #include @@ -404,9 +405,29 @@ const struct cmdinfo cmdinfos[]= { { 0 } }; +static void ident_add_stat(const char *path) { + struct stat stab; + int r = stat(path, &stab); + if (r) diee("failed to stat %s", path); + + IDENT_ADD_OBJ(stab.st_dev); + IDENT_ADD_OBJ(stab.st_ino); +} + void ident_addinit(void) { - char ident_magic[1] = { 0 }; - sha256_update(&identsc, sizeof(ident_magic), ident_magic); + char magic = 1; + + IDENT_ADD_OBJ(magic); + + struct utsname uts = { }; + size_t utslen = sizeof(uts); + int r = uname(&uts); + if (r) diee("uname failed!"); + IDENT_ADD_OBJ(utslen); + IDENT_ADD_OBJ(uts); + + ident_add_stat("."); + ident_add_stat("/"); } static void propagate_exit_status(int status, const char *what) { diff --git a/cprogs/prefork.h b/cprogs/prefork.h index 66ed5fc..cfbd715 100644 --- a/cprogs/prefork.h +++ b/cprogs/prefork.h @@ -88,4 +88,7 @@ void off_ident_addenv(const struct cmdinfo *ci, const char *name); void ident_addinit(void); bool stabs_same_inode(struct stat *a, struct stat *b); +#define IDENT_ADD_OBJ(obj) \ + sha256_update(&identsc, sizeof((obj)), (void*)&obj); + #endif /*PREFORK_H*/