From: Volker Lendecke Date: Tue, 3 Jan 2023 17:41:04 +0000 (+0100) Subject: smbd: Make get_safe_[[SI]VAL|ptr] static to smb1_lanman.c X-Git-Tag: talloc-2.4.0~49 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=158314e0b1df76e87fc3b1cd1260e703a21ce1ca;p=thirdparty%2Fsamba.git smbd: Make get_safe_[[SI]VAL|ptr] static to smb1_lanman.c SMB1-specific, only used there. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 79d424fd10d..d848186b41c 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -359,10 +359,7 @@ uint32_t map_share_mode_to_deny_mode(uint32_t share_access, uint32_t private_opt struct server_id interpret_pid(const char *pid_string); bool is_offset_safe(const char *buf_base, size_t buf_len, char *ptr, size_t off); -char *get_safe_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off); char *get_safe_str_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off); -int get_safe_SVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval); -int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval); bool split_domain_user(TALLOC_CTX *mem_ctx, const char *full_name, char **domain, diff --git a/source3/lib/util.c b/source3/lib/util.c index eef76662f45..8015b7e4604 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1637,16 +1637,6 @@ bool is_offset_safe(const char *buf_base, size_t buf_len, char *ptr, size_t off) return False; } -/**************************************************************** - Return a safe pointer into a buffer, or NULL. -****************************************************************/ - -char *get_safe_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off) -{ - return is_offset_safe(buf_base, buf_len, ptr, off) ? - ptr + off : NULL; -} - /**************************************************************** Return a safe pointer into a string within a buffer, or NULL. ****************************************************************/ @@ -1663,37 +1653,6 @@ char *get_safe_str_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t o return ptr + off; } -/**************************************************************** - Return an SVAL at a pointer, or failval if beyond the end. -****************************************************************/ - -int get_safe_SVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval) -{ - /* - * Note we use off+1 here, not off+2 as SVAL accesses ptr[0] and ptr[1], - * NOT ptr[2]. - */ - if (!is_offset_safe(buf_base, buf_len, ptr, off+1)) { - return failval; - } - return SVAL(ptr,off); -} - -/**************************************************************** - Return an IVAL at a pointer, or failval if beyond the end. -****************************************************************/ - -int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval) -{ - /* - * Note we use off+3 here, not off+4 as IVAL accesses - * ptr[0] ptr[1] ptr[2] ptr[3] NOT ptr[4]. - */ - if (!is_offset_safe(buf_base, buf_len, ptr, off+3)) { - return failval; - } - return IVAL(ptr,off); -} /**************************************************************** Split DOM\user into DOM and user. Do not mix with winbind variants of that diff --git a/source3/smbd/smb1_lanman.c b/source3/smbd/smb1_lanman.c index eb8148753b9..65711078c89 100644 --- a/source3/smbd/smb1_lanman.c +++ b/source3/smbd/smb1_lanman.c @@ -187,6 +187,62 @@ static int StrlenExpanded(connection_struct *conn, int snum, char *s) return strlen(buf) + 1; } +/**************************************************************** + Return an SVAL at a pointer, or failval if beyond the end. +****************************************************************/ + +static int get_safe_SVAL( + const char *buf_base, + size_t buf_len, + char *ptr, + size_t off, + int failval) +{ + /* + * Note we use off+1 here, not off+2 as SVAL accesses ptr[0] + * and ptr[1], NOT ptr[2]. + */ + if (!is_offset_safe(buf_base, buf_len, ptr, off+1)) { + return failval; + } + return SVAL(ptr,off); +} + +/**************************************************************** + Return an IVAL at a pointer, or failval if beyond the end. +****************************************************************/ + +static int get_safe_IVAL( + const char *buf_base, + size_t buf_len, + char *ptr, + size_t off, + int failval) +{ + /* + * Note we use off+3 here, not off+4 as IVAL accesses + * ptr[0] ptr[1] ptr[2] ptr[3] NOT ptr[4]. + */ + if (!is_offset_safe(buf_base, buf_len, ptr, off+3)) { + return failval; + } + return IVAL(ptr,off); +} + +/**************************************************************** + Return a safe pointer into a buffer, or NULL. +****************************************************************/ + +static char *get_safe_ptr( + const char *buf_base, + size_t buf_len, + char *ptr, + size_t off) +{ + return is_offset_safe(buf_base, buf_len, ptr, off) ? + ptr + off : NULL; +} + /******************************************************************* Check a API string for validity when we only need to check the prefix. ******************************************************************/