aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2011-02-14 20:23:12 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-06-06 18:50:11 +0200
commitde706de8c3f67ae8408b2c8be139d177ef5d567c (patch)
tree8bc256ebea3bde9b2eb6cb8d1f87d7694c7c57e5
parent71fa0dc6bb5066e65e43aad90ac3be6219d8b67d (diff)
downloadlibssh-de706de8c3f67ae8408b2c8be139d177ef5d567c.tar.gz
libssh-de706de8c3f67ae8408b2c8be139d177ef5d567c.tar.xz
libssh-de706de8c3f67ae8408b2c8be139d177ef5d567c.zip
Check for NULL pointers in string.c
(cherry picked from commit 4230509e805f546091ca2e4f8aa13c22f6efc7a8)
-rw-r--r--src/string.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/string.c b/src/string.c
index 33920e68..1959ab6f 100644
--- a/src/string.c
+++ b/src/string.c
@@ -92,7 +92,13 @@ int ssh_string_fill(struct ssh_string_struct *s, const void *data, size_t len) {
*/
struct ssh_string_struct *ssh_string_from_char(const char *what) {
struct ssh_string_struct *ptr = NULL;
- size_t len = strlen(what);
+ size_t len;
+
+ if(what == NULL) {
+ return NULL;
+ }
+
+ len = strlen(what);
ptr = malloc(4 + len);
if (ptr == NULL) {
@@ -133,7 +139,7 @@ size_t ssh_string_len(struct ssh_string_struct *s) {
char *ssh_string_to_char(struct ssh_string_struct *s) {
size_t len;
char *new;
- if(s==NULL)
+ if(s==NULL || s->string == NULL)
return NULL;
len = ntohl(s->size) + 1;
new = malloc(len);
@@ -164,7 +170,12 @@ void ssh_string_free_char(char *s) {
* @return Newly allocated copy of the string, NULL on error.
*/
struct ssh_string_struct *ssh_string_copy(struct ssh_string_struct *s) {
- struct ssh_string_struct *new = malloc(ntohl(s->size) + 4);
+ struct ssh_string_struct *new;
+
+ if(s == NULL || s->string == NULL) {
+ return NULL;
+ }
+ new = malloc(ntohl(s->size) + 4);
if (new == NULL) {
return NULL;