Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions util/include/parse_spawn_timeout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef STARTUP_PARSE_SPAWN_TIMEOUT_H
#define STARTUP_PARSE_SPAWN_TIMEOUT_H

#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Parse a full decimal uint32 string. Reject empty, signs, spaces, junk, overflow. */
static inline bool ParseSpawnTimeoutU32(const char *text, uint32_t *out)
{
char *end = NULL;
unsigned long value;

if (text == NULL || out == NULL || *text == '\0') {
return false;
}
/* strtoul accepts leading whitespace and optional sign; reject those. */
if (*text < '0' || *text > '9') {
return false;
}
errno = 0;
value = strtoul(text, &end, 10);
if (errno == ERANGE || end == text || *end != '\0' || value > UINT32_MAX) {
return false;
}
*out = (uint32_t)value;
return true;
}

#ifdef __cplusplus
}
#endif

#endif /* STARTUP_PARSE_SPAWN_TIMEOUT_H */
8 changes: 5 additions & 3 deletions util/src/appspawn_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "appspawn_utils.h"
#include "parse_spawn_timeout.h"

#include <ctype.h>
#include <dirent.h>
Expand Down Expand Up @@ -423,9 +424,10 @@ uint32_t GetSpawnTimeout(uint32_t def, bool isColdRun)
char *key = (isColdRun ? "const.appspawn.reqMgr.asanTimeout" : "persist.appspawn.reqMgr.timeout");
int ret = GetParameter(key, "0", data, sizeof(data));
if (ret > 0 && strcmp(data, "0") != 0) {
errno = 0;
value = (uint32_t)atoi(data);
return (errno != 0) ? def : ((value < def) ? def : value);
if (!ParseSpawnTimeoutU32(data, &value) || value < def) {
return def;
}
return value;
}
return value;
}
Expand Down