mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
Check for NULL pointers in string.c
This commit is contained in:
17
src/string.c
17
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 *ssh_string_from_char(const char *what) {
|
||||||
struct ssh_string_struct *ptr = NULL;
|
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);
|
ptr = malloc(4 + len);
|
||||||
if (ptr == NULL) {
|
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) {
|
char *ssh_string_to_char(struct ssh_string_struct *s) {
|
||||||
size_t len;
|
size_t len;
|
||||||
char *new;
|
char *new;
|
||||||
if(s==NULL)
|
if(s==NULL || s->string == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
len = ntohl(s->size) + 1;
|
len = ntohl(s->size) + 1;
|
||||||
new = malloc(len);
|
new = malloc(len);
|
||||||
@@ -164,7 +170,12 @@ void ssh_string_free_char(char *s) {
|
|||||||
* @return Newly allocated copy of the string, NULL on error.
|
* @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 *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) {
|
if (new == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user