diff options
Diffstat (limited to 'contrib/ntp/sntp/libopts/compat/pathfind.c')
-rw-r--r-- | contrib/ntp/sntp/libopts/compat/pathfind.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/contrib/ntp/sntp/libopts/compat/pathfind.c b/contrib/ntp/sntp/libopts/compat/pathfind.c index 5c477ca..d343dcc 100644 --- a/contrib/ntp/sntp/libopts/compat/pathfind.c +++ b/contrib/ntp/sntp/libopts/compat/pathfind.c @@ -115,9 +115,15 @@ make_absolute( char const * string, char const * dot_path ) if (!dot_path || *string == '/') { result = strdup( string ); + if (result == NULL) { + return NULL; /* couldn't allocate memory */ + } } else { if (dot_path && dot_path[0]) { result = malloc( 2 + strlen( dot_path ) + strlen( string ) ); + if (result == NULL) { + return NULL; /* couldn't allocate memory */ + } strcpy( result, dot_path ); result_len = (int)strlen(result); if (result[result_len - 1] != '/') { @@ -126,6 +132,9 @@ make_absolute( char const * string, char const * dot_path ) } } else { result = malloc( 3 + strlen( string ) ); + if (result == NULL) { + return NULL; /* couldn't allocate memory */ + } result[0] = '.'; result[1] = '/'; result[2] = '\0'; result_len = 2; } @@ -155,7 +164,9 @@ canonicalize_pathname( char *path ) /* The result cannot be larger than the input PATH. */ result = strdup( path ); - + if (result == NULL) { + return NULL; /* couldn't allocate memory */ + } stub_char = (*path == '/') ? '/' : '.'; /* Walk along RESULT looking for things to compact. */ |