1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

smbd/notify: Handle allocation failure

If a talloc function returns NULL, indicating failure, the failure could
be masked by the next talloc call allocating on the NULL context.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Joseph Sutton 2023-02-13 14:58:52 +13:00 committed by Andreas Schneider
parent a1e64e5737
commit 78ca3e16da

View File

@ -864,33 +864,83 @@ char *notify_filter_string(TALLOC_CTX *mem_ctx, uint32_t filter)
char *result = NULL;
result = talloc_strdup(mem_ctx, "");
if (result == NULL) {
return NULL;
}
if (filter & FILE_NOTIFY_CHANGE_FILE_NAME)
if (filter & FILE_NOTIFY_CHANGE_FILE_NAME) {
result = talloc_asprintf_append(result, "FILE_NAME|");
if (filter & FILE_NOTIFY_CHANGE_DIR_NAME)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_DIR_NAME) {
result = talloc_asprintf_append(result, "DIR_NAME|");
if (filter & FILE_NOTIFY_CHANGE_ATTRIBUTES)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_ATTRIBUTES) {
result = talloc_asprintf_append(result, "ATTRIBUTES|");
if (filter & FILE_NOTIFY_CHANGE_SIZE)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_SIZE) {
result = talloc_asprintf_append(result, "SIZE|");
if (filter & FILE_NOTIFY_CHANGE_LAST_WRITE)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_LAST_WRITE) {
result = talloc_asprintf_append(result, "LAST_WRITE|");
if (filter & FILE_NOTIFY_CHANGE_LAST_ACCESS)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_LAST_ACCESS) {
result = talloc_asprintf_append(result, "LAST_ACCESS|");
if (filter & FILE_NOTIFY_CHANGE_CREATION)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_CREATION) {
result = talloc_asprintf_append(result, "CREATION|");
if (filter & FILE_NOTIFY_CHANGE_EA)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_EA) {
result = talloc_asprintf_append(result, "EA|");
if (filter & FILE_NOTIFY_CHANGE_SECURITY)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_SECURITY) {
result = talloc_asprintf_append(result, "SECURITY|");
if (filter & FILE_NOTIFY_CHANGE_STREAM_NAME)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_STREAM_NAME) {
result = talloc_asprintf_append(result, "STREAM_NAME|");
if (filter & FILE_NOTIFY_CHANGE_STREAM_SIZE)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_STREAM_SIZE) {
result = talloc_asprintf_append(result, "STREAM_SIZE|");
if (filter & FILE_NOTIFY_CHANGE_STREAM_WRITE)
if (result == NULL) {
return NULL;
}
}
if (filter & FILE_NOTIFY_CHANGE_STREAM_WRITE) {
result = talloc_asprintf_append(result, "STREAM_WRITE|");
if (result == NULL) {
return NULL;
}
}
if (result == NULL) return NULL;
if (*result == '\0') return result;
result[strlen(result)-1] = '\0';