Skip to content

Commit cb83165

Browse files
committed
add more assert like NULL checks
Ensure the code will not crash under unlikely conditions of pointers that are guaranteed to not be NULL being NULL.
1 parent af1170a commit cb83165

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

agent/lib_composer.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ static char* nr_execute_handle_autoload_composer_get_vendor_path(
163163
char* vendor_path = NULL; // result of dirname(filename)
164164
char* cp = NULL;
165165

166+
// nrunlikely because this should alredy be ensured by the caller
167+
if (nrunlikely(NULL == filename)) {
168+
nrl_verbosedebug(NRL_FRAMEWORK, "%s - filename is NULL", __func__);
169+
return NULL;
170+
}
171+
166172
// vendor_path = dirname(filename):
167173
// 1. copy filename to vendor_path
168174
vendor_path = nr_strdup(filename);
@@ -180,6 +186,18 @@ static bool nr_execute_handle_autoload_composer_file_exists(
180186
char* composer_magic_file = NULL; // vendor_path + filename
181187
bool file_exists = false;
182188

189+
// nrunlikely because this should alredy be ensured by the caller
190+
if (nrunlikely(NULL == vendor_path)) {
191+
nrl_verbosedebug(NRL_FRAMEWORK, "%s - vendor_path is NULL", __func__);
192+
return false;
193+
}
194+
195+
// nrunlikely because this should alredy be ensured by the caller
196+
if (nrunlikely(NULL == filename)) {
197+
nrl_verbosedebug(NRL_FRAMEWORK, "%s - filename is NULL", __func__);
198+
return false;
199+
}
200+
183201
composer_magic_file = nr_formatf("%s/%s", vendor_path, filename);
184202
if (0 == nr_access(composer_magic_file, F_OK | R_OK)) {
185203
file_exists = true;
@@ -199,6 +217,12 @@ void nr_composer_handle_autoload(const char* filename) {
199217
#define COMPOSER_MAGIC_FILE_3_LEN (sizeof(COMPOSER_MAGIC_FILE_3) - 1)
200218
char* vendor_path = NULL; // result of dirname(filename)
201219

220+
// nrunlikely because this should alredy be ensured by the caller
221+
if (nrunlikely(NULL == filename)) {
222+
nrl_verbosedebug(NRL_FRAMEWORK, "%s - filename is NULL", __func__);
223+
return;
224+
}
225+
202226
vendor_path = nr_execute_handle_autoload_composer_get_vendor_path(filename);
203227
if (NULL == vendor_path) {
204228
nrl_verbosedebug(NRL_FRAMEWORK, "unable to get vendor path from '%s'",

0 commit comments

Comments
 (0)