summaryrefslogtreecommitdiffstats
path: root/src/4a-internals-hal/4a-internals-hal-cb.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-22 15:12:11 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-24 16:31:22 +0200
commit06054f68c5d5ca216f2756e7de2787a7ea2b9488 (patch)
tree45332bf88713260528cd8807180d14c796dd0d68 /src/4a-internals-hal/4a-internals-hal-cb.c
parent701bea793ed1d2e20d036957268a71973c975cda (diff)
Add forgotten verifications of allocation results
Concern several types of allocation such as : - malloc/calloc - json_object_new_* - wrap_json_pack - strdup BUG-AGL: SPEC-2329 Change-Id: Iffe2a6a44ef4df2ed0ec4d159682159db5e78cfb Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'src/4a-internals-hal/4a-internals-hal-cb.c')
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c124
1 files changed, 93 insertions, 31 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index ee0787b..bca4d82 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -276,11 +276,16 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
if(alsaMap->ctl.value) {
// TBD JAI : handle alsa controls type
valueJ = json_object_new_int(alsaMap->ctl.value);
+ if(! valueJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate ALSA control value json string");
+ return -4;
+ }
+
err = 0;
if(InternalHalConvertJsonValues(apiHandle, &alsaMap->ctl.alsaCtlProperties, valueJ, &convertedValueJ, CONVERSION_NORMALIZED_TO_ALSACORE)) {
AFB_API_ERROR(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ));
- err = -4;
+ err = -5;
}
else if(InternalHalSetAlsaCtlValue(apiHandle, cardId, alsaMap->ctl.numid, convertedValueJ)) {
AFB_API_ERROR(apiHandle,
@@ -288,7 +293,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
alsaMap->ctl.numid,
cardId,
json_object_get_string(valueJ));
- err = -5;
+ err = -6;
}
json_object_put(valueJ);
@@ -302,11 +307,18 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
if(alsaMap->actionJ) {
alsaMap->action = calloc(1, sizeof(CtlActionT));
+ if(! alsaMap->action) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate structure used to store action to perform"
+ "when the corresponding ALSA control is detected");
+ return -7;
+ }
+
if(ActionLoadOne(apiHandle, alsaMap->action, alsaMap->actionJ, 0)) {
AFB_API_ERROR(apiHandle,
"Didn't succeed to load action using alsa object : '%s'",
json_object_get_string(alsaMap->actionJ));
- return -6;
+ return -8;
}
}
@@ -314,7 +326,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
AFB_API_ERROR(apiHandle,
"Didn't succeed to create verb for current alsa control to load action using alsa object : '%s'",
json_object_get_string(alsaMap->actionJ));
- return -7;
+ return -9;
}
return 0;
@@ -346,6 +358,10 @@ int InternalHalProcessAllHalMap(afb_api_t apiHandle, json_object *AlsaMapJ, stru
}
ctlMaps = calloc(currentInternalHalAlsaMapT->ctlsCount, sizeof(struct InternalHalAlsaMap));
+ if(! ctlMaps) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate halmap data table");
+ return -2;
+ }
for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++)
err += InternalHalProcessOneHalMapObject(apiHandle, &ctlMaps[idx], alsaMapType == json_type_array ? json_object_array_get_idx(AlsaMapJ, idx) : AlsaMapJ);
@@ -386,11 +402,15 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
if(AlsaMapJ) {
currentHalData->internalHalData->alsaMapT = calloc(1, sizeof(struct InternalHalAlsaMapT));
+ if(! currentHalData->internalHalData->alsaMapT) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate data structure used to store halmap data table");
+ return -3;
+ }
if(InternalHalProcessAllHalMap(apiHandle, AlsaMapJ, currentHalData->internalHalData->alsaMapT)) {
AFB_API_ERROR(apiHandle, "Failed to process 'halmap' section");
HalUtlFreeAlsaCtlsMap(currentHalData->internalHalData->alsaMapT);
- return -3;
+ return -4;
}
}
else if(currentHalData->status == HAL_STATUS_UNAVAILABLE) {
@@ -399,7 +419,7 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
}
else if(currentHalData->sndCardId < 0) {
AFB_API_ERROR(apiHandle, "Hal alsa card id is not valid, 'halmap' section data can't be handle");
- return -4;
+ return -5;
}
else if(! currentHalData->internalHalData->alsaMapT) {
AFB_API_WARNING(apiHandle, "'halmap' section data is empty");
@@ -411,7 +431,7 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
}
else if(InternalHalHandleAllHalMap(apiHandle, currentHalData->sndCardId, currentHalData->internalHalData->alsaMapT)) {
AFB_API_ERROR(apiHandle, "Failed to handle 'halmap' section");
- return -5;
+ return -6;
}
return 0;
@@ -425,6 +445,8 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle,
struct InternalHalMixerData **mixerDataList,
enum MixerDataType dataType)
{
+ int wrapRet;
+
json_object *mixerDataArrayJ, *currentMixerDataJ;
struct InternalHalMixerData *currentMixerData;
@@ -444,25 +466,32 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle,
while(currentMixerData) {
switch(dataType) {
case MIXER_DATA_STREAMS:
- wrap_json_pack(&currentMixerDataJ,
- "{s:s s:s}",
- "name", currentMixerData->verb,
- "cardId", currentMixerData->streamCardId);
+ wrapRet = wrap_json_pack(&currentMixerDataJ,
+ "{s:s s:s}",
+ "name", currentMixerData->verb,
+ "cardId", currentMixerData->streamCardId);
break;
case MIXER_DATA_PLAYBACKS:
case MIXER_DATA_CAPTURES :
- wrap_json_pack(&currentMixerDataJ,
- "{s:s s:s}",
- "name", currentMixerData->verb,
- "mixer-name", currentMixerData->verbToCall,
- "uid", currentMixerData->streamCardId ? currentMixerData->streamCardId : "none");
+ wrapRet = wrap_json_pack(&currentMixerDataJ,
+ "{s:s s:s}",
+ "name", currentMixerData->verb,
+ "mixer-name", currentMixerData->verbToCall,
+ "uid", currentMixerData->streamCardId ? currentMixerData->streamCardId : "none");
break;
default:
json_object_put(mixerDataArrayJ);
return NULL;
}
+
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate current mixer/playbacks/captures json object");
+ json_object_put(mixerDataArrayJ);
+ return NULL;
+ }
+
json_object_array_add(mixerDataArrayJ, currentMixerDataJ);
currentMixerData = currentMixerData->next;
@@ -473,6 +502,7 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle,
json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct InternalHalAlsaMapT *currentAlsaMapDataT)
{
+ int wrapRet;
unsigned int idx;
json_object *alsaMapDataArray, *currentAlsaMapData;
@@ -494,10 +524,15 @@ json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct Inte
}
for(idx = 0; idx < currentAlsaMapDataT->ctlsCount; idx++) {
- wrap_json_pack(&currentAlsaMapData,
- "{s:s s:s}",
- "name", currentAlsaMapDataT->ctls[idx].uid,
- "info", currentAlsaMapDataT->ctls[idx].info ? currentAlsaMapDataT->ctls[idx].info : "none");
+ wrapRet = wrap_json_pack(&currentAlsaMapData,
+ "{s:s s:s}",
+ "name", currentAlsaMapDataT->ctls[idx].uid,
+ "info", currentAlsaMapDataT->ctls[idx].info ? currentAlsaMapDataT->ctls[idx].info : "none");
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate current mixer/playbacks/captures json object");
+ json_object_put(alsaMapDataArray);
+ return NULL;
+ }
json_object_array_add(alsaMapDataArray, currentAlsaMapData);
}
@@ -507,6 +542,8 @@ json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct Inte
void InternalHalInfo(afb_req_t request)
{
+ int wrapRet;
+
char *apiToCall, *returnedError = NULL, *returnedInfo = NULL;
afb_api_t apiHandle;
@@ -595,12 +632,22 @@ void InternalHalInfo(afb_req_t request)
return;
}
- wrap_json_pack(&requestAnswer,
- "{s:o s:o s:o s:o}",
- "streams", streamsArray,
- "playbacks", playbacksArray,
- "captures", capturesArray,
- "controls", controlsArray);
+ wrapRet = wrap_json_pack(&requestAnswer,
+ "{s:o s:o s:o s:o}",
+ "streams", streamsArray,
+ "playbacks", playbacksArray,
+ "captures", capturesArray,
+ "controls", controlsArray);
+ if(wrapRet) {
+ afb_req_fail(request,
+ "halinfo_json_object",
+ "Didn't succeed to allocate hal info response json object");
+ json_object_put(streamsArray);
+ json_object_put(playbacksArray);
+ json_object_put(capturesArray);
+ json_object_put(controlsArray);
+ return;
+ }
afb_req_success(request, requestAnswer, "Requested data");
}
@@ -618,7 +665,10 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib
struct InternalHalMixerData *currentStreamData;
struct InternalHalAlsaMapT *InternalHalAlsaMapT;
- json_object *requestJson, *requestedSubscriptionsJ, *requestedSubscriptionJ = NULL;
+ json_object *requestJson,
+ *requestedSubscriptionsJ,
+ *requestedSubscriptionJ = NULL,
+ *subscriptionDoneNbJ = NULL;
json_type requestJsonType;
apiHandle = afb_req_get_api(request);
@@ -770,27 +820,39 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib
}
}
- if(subscriptionDoneNb == 0)
+ if(! subscriptionDoneNb) {
afb_req_fail_f(request,
"events_not_found",
"%s failed, event(s) were not found",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription");
+ return;
+ }
+ else {
+ subscriptionDoneNbJ = json_object_new_int(subscriptionDoneNb);
+ if(! subscriptionDoneNbJ) {
+ afb_req_fail(request,
+ "subscriptionnb_json_integer",
+ "Didn't succeed to allocate subscription number json integer");
+ return;
+ }
+ }
+
if(subscriptionDoneNb == count)
afb_req_success_f(request,
- json_object_new_int(subscriptionDoneNb),
+ subscriptionDoneNbJ,
"%s succeed for all the %i events requested",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription",
subscriptionDoneNb);
else if(subscriptionDoneNb < count)
afb_req_success_f(request,
- json_object_new_int(subscriptionDoneNb),
+ subscriptionDoneNbJ,
"%s succeed but only to %i events requested out of %i",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription",
subscriptionDoneNb,
count);
else
afb_req_success_f(request,
- json_object_new_int(subscriptionDoneNb),
+ subscriptionDoneNbJ,
"%s succeed but to more events than requested (%i out of %i)",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription",
subscriptionDoneNb,