aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-15misc.c: Initialize pointers and free itNorbert Pocs1-2/+4
Signed-off-by: Norbert Pocs <norbertpocs0@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2024-01-15Check any input username for validityNorbert Pocs1-2/+8
Check possible inputs of username for malicious code. Signed-off-by: Norbert Pocs <norbertpocs0@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2024-01-15misc: Add function to check username syntaxNorbert Pocs1-0/+32
Malicious code can be injected using the username with metacharacters, therefore the username must be validated before using it with any %u. Signed-off-by: Norbert Pocs <norbertpocs0@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-18CVE-2023-6004: misc: Add ipv6 link-local check for an ip addressNorbert Pocs1-6/+38
Signed-off-by: Norbert Pocs <norbertpocs0@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-18CVE-2023-6004: misc: Add function to check allowed characters of a hostnameNorbert Pocs1-0/+68
The hostname can be a domain name or an ip address. The colon has to be allowed because of IPv6 even it is prohibited in domain names. Signed-off-by: Norbert Pocs <norbertpocs0@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-08-22misc.c : Introduce ssh_writen()Eshan Kelkar1-0/+51
A call to write() may perform a short write on a local file. To avoid short writes, ssh_writen() can be used. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-08-22misc.c : Introduce ssh_readn()Eshan Kelkar1-0/+60
A call to read() may peform a short read from a local file even when sufficient data is present in the file. ssh_readn() can be used instead of read() to avoid such short reads. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-07-11misc: Reformat allocation checksJakub Jelen1-3/+5
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2022-11-29misc.c: Fix typo in docstringNorbert Pocs1-1/+1
Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-11-02misc.c/h: Change function parameter nameNorbert Pocs1-5/+5
"template" is a c++ keyword which will make the build fail. Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-10-07SSH_LOG_DEBUG: Recategorize loglevelsNorbert Pocs1-4/+4
Loglevel INFO is the default openssh configuration setting which does not print redundant information. On a system using openssh with loglevels set by the terms of openssh will cause unwanted log lines in the output. recategorized based on - SSH_LOG_DEBUG are informational debug logs (no error) Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-10-07SSH_LOG_TRACE: Recategorize loglevelsNorbert Pocs1-4/+4
Do not print out logs when no fatal error happens. This approach is similiar to openssh, when Error/Fatal does not print recoverable error logs. recategorized based on - SSH_LOG_TRACE are debug logs when error happens Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-09-29misc.c: Remove dot from documentation group definitionNorbert Pocs1-1/+1
Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-08-30misc: Refactor ssh_strerror to check return valuesJakub Jelen1-7/+15
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-08-30Do not force GNU_SOURCE during build to fix #141Jakub Jelen1-1/+1
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-08-29misc: Fix expanding port numbersAndreas Schneider1-1/+1
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-08-26misc: Fix format truncation in ssh_path_expand_escape()Andreas Schneider1-8/+7
error: ā€˜%uā€™ directive output may be truncated writing between 1 and 10 bytes into a region of size 6. Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-08-25misc: rename gettimeofday symbolTimo Rothenpieler1-1/+1
mingw does have this function, even though it appears to be deprecated. So the symbol has to have a different name, or linking becomes impossible. Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-07-07misc: FreeBSD compatible strerror_r usageJakub Jelen1-3/+5
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-07-04Add ssh_strerror functionNorbert Pocs1-0/+24
- strerror_r for linux - strerror_s for windows Keep in mind that strerror_r has two versions: - XSI - GNU see manpage for more information Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-06-15Fix type mismatch warningsNorbert Pocs1-8/+13
Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-06-09Add errno reset with strtoul callNorbert Pocs1-0/+4
Contaminated errno can happen before strtoul call, thereofore cleaning it before the call. The errno is not used for checking later in code if fail happens, therefore cleaning it right after error. Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-06-09Reformat most of the function headersJakub Jelen1-90/+123
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-06-09Improve documentation by mentioning the free functionsJakub Jelen1-6/+21
Related: https://gitlab.com/libssh/libssh-mirror/-/issues/3 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2022-05-02Fix multiple spelling and grammar mistakesJunda Ai1-8/+9
Signed-off-by: Junda Ai <aijunda29@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2022-02-10misc: Initialize the host bufferJakub Jelen1-1/+1
This fails if the gethostname() fails in a way that does not write the buffer, but returns 0 as a success. Fixes #106 Thanks oss-fuzz Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2021-11-02client configuration fuzzing and fixesStanislav Zidek1-3/+27
Signed-off-by: Stanislav Zidek <szidek@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2021-06-16misc: Avoid the 4KB stack buffer in ssh_path_expand_escapeXiang Xiao1-5/+23
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: I908ef4dfa960bf89f8e42f99af2f8bcdbb006bc8
2021-06-10windows: Define PATH_MAX to MAX_PATHXiang Xiao1-1/+1
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Change-Id: Ib3358ecb029d93c263d3cb39da25e82a772ae2c7
2020-09-17misc: Do not call random()Anderson Toshiyuki Sasaki1-10/+13
Avoid calling random() and use ssh_get_random() instead. CID #1412376 Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2020-07-16misc: Do not confuse client/server in debug messagesJakub Jelen1-1/+2
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2020-01-23misc: Make the src pointer const in ssh_strreplace()Andreas Schneider1-1/+1
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2020-01-23misc: Simplifies ssh_strreplace().Sahana Prasad1-13/+14
Signed-off-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-20misc: Add ssh_strreplace()Andreas Schneider1-0/+50
Pair-Programmed-With: Sahana Prasad <sahana@redhat.com> Signed-Off-by: Sahana Prasad <sahana@redhat.com> Signed-Off-By: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-20misc: Add ssh_tmpname()Andreas Schneider1-0/+51
Signed-Off-By: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09misc: Add a function to encode newlinesAnderson Toshiyuki Sasaki1-0/+43
Given a string, the added function encodes existing newline characters ('\n') as the string "\\n" and puts into a given output buffer. The output buffer must have at least 2 times the length of the input string plus 1 for the terminating '\0'. In the worst case, each character can be replaced by 2 characters. Fixes T189 Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2019-12-09CVE-2019-14889: misc: Add function to quote file namesAnderson Toshiyuki Sasaki1-0/+184
The added function quote file names strings to be used in a shell. Special cases are treated for the charactes '\'' and '!'. Fixes T181 Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-08-06misc: Introduce internal function ssh_mkdirs()Anderson Toshiyuki Sasaki1-5/+70
If the given path includes missing directories, ssh_mkdirs() tries to create them recursively. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-08-06misc: Introduce internal function ssh_dir_writeable()Anderson Toshiyuki Sasaki1-0/+50
The introduced internal function checks if the provided path is for an existing directory which is accessible for writing. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-07-30misc: Allow %% to escape a single % in paths.Richard W.M. Jones1-0/+3
For example "%d/config%%1" is expanded to "~/.ssh/config%1". Signed-off-by: Richard W.M. Jones <rjones@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-07-30misc: Introduce ssh_log_hexdump()Anderson Toshiyuki Sasaki1-0/+187
The introduced internal function is intended to be a replacement for the deprecated function ssh_print_hexa(). Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-06-13SSH_LOG: Adjust log level from SSH_LOG_WARNING to SSH_LOG_PROTOCOLDavid Wedderwille1-2/+2
Fixes T149 Signed-off-by: David Wedderwille <davidwe@posteo.de> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14Reformat ssh_hostport()Jakub Jelen1-7/+13
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-03-29misc: Avoid printing full path in debug messageAlberto Garcia Illera1-2/+2
Signed-off-by: Alberto Garcia Illera <agarciaillera@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-02-07include: Mark ssh_print_hexa as deprecatedAndreas Schneider1-7/+1
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2019-01-26misc: Add NULL checks before accessing listsAnderson Toshiyuki Sasaki1-8/+33
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-01-24dh: move unrelated functions out of dh.cAris Adamantiadis1-0/+57
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2018-10-30misc: Properly check for errors returned from getpwuid_r()Jakub Jelen1-4/+4
Resolves: T118 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2018-10-30misc: Reformat ssh_get_user_home_dir and ssh_file_readaccess_okJakub Jelen1-25/+28
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2018-10-09libmbedtls: Support OpenSSH-compatible AES-GCM ciphers using mbedTLSJakub Jelen1-0/+13
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>