Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ota/fix sudo issue #1487

Merged
merged 24 commits into from
Dec 14, 2020
Merged
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
570da97
Fix sudo file path issue
pvyawaha Dec 12, 2020
93f803f
fix path for update file
pvyawaha Dec 12, 2020
8dea7a1
fix compiler warning
pvyawaha Dec 12, 2020
05922a2
Update platform/posix/ota_pal/source/ota_pal_posix.c
pvyawaha Dec 12, 2020
c6a48f2
fix ut
divekarshubham Dec 12, 2020
130011b
fix ut
divekarshubham Dec 12, 2020
2445cb9
Dump platform image state path on error
pvyawaha Dec 12, 2020
8e4aebf
Update submodule ptr
divekarshubham Dec 13, 2020
024456d
Remove snprintf mock since it's not being used
yanjos-dev Dec 13, 2020
6355e90
Remove remaining usage of snprintf in OTA PAL tests
yanjos-dev Dec 13, 2020
55d100b
Add getcwd mock to OTA PAL unit tests
yanjos-dev Dec 13, 2020
8853b8e
Remove unused variable from OTA PAl tests
yanjos-dev Dec 13, 2020
2af54c1
Merge branch 'main' of github.com:aws/aws-iot-device-sdk-embedded-C i…
divekarshubham Dec 13, 2020
9627a0a
Extracting file path generation in a separate function
divekarshubham Dec 13, 2020
7b0541a
Removing unused variables
divekarshubham Dec 13, 2020
5bf5d25
Add OTA PAL test for long file paths
yanjos-dev Dec 13, 2020
7a5c6a3
Addressing PR comments
divekarshubham Dec 14, 2020
4504c03
Merge UT changes
divekarshubham Dec 14, 2020
4784e65
spell fix
divekarshubham Dec 14, 2020
a3d852d
Refactoring to use status and spell fix
divekarshubham Dec 14, 2020
28c31fa
Fix OTA PAL test asserts
yanjos-dev Dec 14, 2020
28d0453
Remove unused variable
yanjos-dev Dec 14, 2020
8e4a008
Using strcat instead on strncat and ota submodule update
divekarshubham Dec 14, 2020
bcf7882
Merge branch 'ota/fix_sudo_issue' of github.com:aws/aws-iot-device-sd…
divekarshubham Dec 14, 2020
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
82 changes: 54 additions & 28 deletions platform/posix/ota_pal/source/ota_pal_posix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* OTA PAL V2.0.0 (Release Candidate) for POSIX
* OTA PAL for POSIX V2.0.0
pvyawaha marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
Expand Down Expand Up @@ -30,6 +30,7 @@
#include <errno.h>
#include <assert.h>
#include <libgen.h>
#include <unistd.h>
divekarshubham marked this conversation as resolved.
Show resolved Hide resolved

#include "ota.h"
#include "ota_pal_posix.h"
Expand Down Expand Up @@ -57,7 +58,12 @@ static const char signingcredentialSIGNING_CERTIFICATE_PEM[] = "Paste code signi
/**
* @brief Size of buffer used in file operations on this platform (POSIX).
*/
#define OTA_PAL_POSIX_BUF_SIZE ( ( size_t ) 4096U )
#define OTA_PAL_POSIX_BUF_SIZE ( ( size_t ) 4096U )

/**
* @brief Name of the file used for storing platform image state.
*/
#define OTA_PLATFORM_IMAGE_STATE_FILE "/PlatformImageState.txt"

/**
* @brief Specify the OTA signature algorithm we support on this platform.
Expand Down Expand Up @@ -374,11 +380,19 @@ OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C )
{
if( C->pFilePath[ 0 ] != ( uint8_t ) '/' )
{
/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
int res = snprintf( realFilePath, OTA_FILE_PATH_LENGTH_MAX, "%s/%s", getenv( "PWD" ), C->pFilePath );
assert( res >= 0 );
( void ) res; /* Suppress the unused variable warning when assert is off. */
/* Get current directory. */
char * pFileName = getcwd( realFilePath, OTA_FILE_PATH_LENGTH_MAX );

if( pFileName == NULL )
{
LogError( ( "Failed to get current working directory: %s", strerror( errno ) ) );
}
else
{
/* Add the filename . */
realFilePath[ strlen( realFilePath ) ] = '/';
cobusve marked this conversation as resolved.
Show resolved Hide resolved
strncat( realFilePath, ( char * ) C->pFilePath, strlen( ( const char * ) C->pFilePath ) + 1U );
cobusve marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
{
Expand Down Expand Up @@ -541,22 +555,28 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const C,
OtaPalMainStatus_t mainErr = OtaPalBadImageState;
int32_t subErr = 0;
FILE * pPlatformImageState = NULL;
char imageStateFile[ OTA_FILE_PATH_LENGTH_MAX ];

char imageStateFile[ OTA_FILE_PATH_LENGTH_MAX ] = { 0 };

( void ) C;

if( ( eState != OtaImageStateUnknown ) && ( eState <= OtaLastImageState ) )
{
/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
int res = snprintf( imageStateFile, OTA_FILE_PATH_LENGTH_MAX, "%s/%s", getenv( "PWD" ), "PlatformImageState.txt" );
assert( res >= 0 );
( void ) res; /* Suppress the unused variable warning when assert is off. */
/* Get current directory. */
char * pFileName = getcwd( imageStateFile, OTA_FILE_PATH_LENGTH_MAX );

/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
pPlatformImageState = fopen( imageStateFile, "w+b" );
if( pFileName == NULL )
{
LogError( ( "Failed to get current working directory: %s", strerror( errno ) ) );
}
else
{
/* Add the filename . */
strncat( imageStateFile, OTA_PLATFORM_IMAGE_STATE_FILE, sizeof( OTA_PLATFORM_IMAGE_STATE_FILE ) );
cobusve marked this conversation as resolved.
Show resolved Hide resolved

/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
pPlatformImageState = fopen( imageStateFile, "w+b" );
}

if( pPlatformImageState != NULL )
{
Expand Down Expand Up @@ -626,23 +646,29 @@ OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t * const C )
*/
OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const C )
{
FILE * pPlatformImageState;
FILE * pPlatformImageState = NULL;
OtaImageState_t eSavedAgentState = OtaImageStateUnknown;
OtaPalImageState_t ePalState = OtaPalImageStateUnknown;
char imageStateFile[ OTA_FILE_PATH_LENGTH_MAX ];
char imageStateFile[ OTA_FILE_PATH_LENGTH_MAX ] = { 0 };

/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
int res = snprintf( imageStateFile, OTA_FILE_PATH_LENGTH_MAX, "%s/%s", getenv( "PWD" ), "PlatformImageState.txt" );
( void ) C;

assert( res >= 0 );
( void ) res; /* Suppress the unused variable warning when assert is off. */
/* Get current directory. */
char * pFileName = getcwd( imageStateFile, OTA_FILE_PATH_LENGTH_MAX );

( void ) C;
if( pFileName == NULL )
{
LogError( ( "Failed to get current working directory: %s", strerror( errno ) ) );
}
else
{
/* Add the filename . */
strncat( imageStateFile, OTA_PLATFORM_IMAGE_STATE_FILE, sizeof( OTA_PLATFORM_IMAGE_STATE_FILE ) );
cobusve marked this conversation as resolved.
Show resolved Hide resolved

/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
pPlatformImageState = fopen( imageStateFile, "r+b" );
/* POSIX port using standard library */
/* coverity[misra_c_2012_rule_21_6_violation] */
pPlatformImageState = fopen( imageStateFile, "r+b" );
}

if( pPlatformImageState != NULL )
{
Expand Down