File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
features/cellular/framework/AT Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -722,7 +722,19 @@ int32_t ATHandler::read_int()
722722 return -1 ;
723723 }
724724
725- return std::strtol (buff, NULL , 10 );
725+ errno = 0 ;
726+ char *endptr;
727+ long result = std::strtol (buff, &endptr, 10 );
728+ if ((result == LONG_MIN || result == LONG_MAX) && errno == ERANGE) {
729+ return -1 ; // overflow/underflow
730+ }
731+ if (result < 0 ) {
732+ return -1 ; // negative values are unsupported
733+ }
734+ if (*buff == ' \0 ' ) {
735+ return -1 ; // empty string
736+ }
737+ return (int32_t ) result;
726738}
727739
728740void ATHandler::set_delimiter (char delimiter)
Original file line number Diff line number Diff line change @@ -416,9 +416,9 @@ class ATHandler {
416416 */
417417 ssize_t read_hex_string (char *str, size_t size);
418418
419- /* * Reads as string and converts result to integer. Supports only positive integers.
419+ /* * Reads as string and converts result to integer. Supports only non-negative integers.
420420 *
421- * @return the positive integer or -1 in case of error.
421+ * @return the non-negative integer or -1 in case of error.
422422 */
423423 int32_t read_int ();
424424
You can’t perform that action at this time.
0 commit comments