“Buffer Overflow - Array Index Out of Bounds” when arrays sizes are correctly managed Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?Why is there no Z80 like LDIR functionality in C/C++/rtl?Improve INSERT-per-second performance of SQLite?ABR - Klocwork false alarms and incorrect bug disposalOdd Klockwork finding (Buffer overflow)how string are represented in memory in cC socket sending multiple fields message with binary protocolUsing '*' as 'value at' operator in CABR Analyze Buffer overflow - Klockwork issueHandling an array of pointersHow to prevent Buffer overflow / array overflow?

What do you call a plan that's an alternative plan in case your initial plan fails?

How much radiation do nuclear physics experiments expose researchers to nowadays?

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

Models of set theory where not every set can be linearly ordered

Is there a concise way to say "all of the X, one of each"?

What LEGO pieces have "real-world" functionality?

Stars Make Stars

If Jon Snow became King of the Seven Kingdoms what would his regnal number be?

Super Attribute Position on Product Page Magento 1

If a contract sometimes uses the wrong name, is it still valid?

"Seemed to had" is it correct?

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

Why does Python start at index -1 when indexing a list from the end?

Sorting numerically

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

What causes the vertical darker bands in my photo?

Why is black pepper both grey and black?

Diagram with tikz

What would be the ideal power source for a cybernetic eye?

How to do this path/lattice with tikz

Single word antonym of "flightless"

How does a Death Domain cleric's Touch of Death feature work with Touch-range spells delivered by familiars?

Why is there no army of Iron-Mans in the MCU?

Dominant seventh chord in the major scale contains diminished triad of the seventh?



“Buffer Overflow - Array Index Out of Bounds” when arrays sizes are correctly managed



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?Why is there no Z80 like LDIR functionality in C/C++/rtl?Improve INSERT-per-second performance of SQLite?ABR - Klocwork false alarms and incorrect bug disposalOdd Klockwork finding (Buffer overflow)how string are represented in memory in cC socket sending multiple fields message with binary protocolUsing '*' as 'value at' operator in CABR Analyze Buffer overflow - Klockwork issueHandling an array of pointersHow to prevent Buffer overflow / array overflow?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-3















I'm getting "Buffer Overflow - Array Index Out of Bounds" for the following code :



typedef struct 
char apn[100 + 1];
char user[22 + 1];
char pass[22 + 1];
GprsParam_t;
typedef struct IfConfig_s
Eth_t eth;
Gprs_t gprs;
Wifi_t wifi;
IfConfig_t;
typedef struct
char apn[64];
char user[32];
char pass[16];
Gprs_t;
gprsParam_t accessPoint;
memset(accessPoint, 0x00, sizeof(accessPoint);
memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn));


I'm trying to copy the value of apn in Gprs_t struct to apn in gprsParam_t
when the sizeof accessPoint.apn is 100 while the sizeof gprs.accessPoint.apn is 64. but it's causing klockwork issue :
Array 'apn' of size 64 may use index value(s) 64..100



I need help understanding this issue.










share|improve this question
























  • What is accessPoint.apn? What is gprs.accessPoint.apn? Please create a Minimal, Complete, and Verifiable example that replicates your problem to show us. Also please take some time to refresh how to ask good questions, as well as this question checklist.

    – Some programmer dude
    Mar 22 at 8:40












  • We need to see a Minimal, Complete, and Verifiable example for this problem.

    – Sourav Ghosh
    Mar 22 at 8:40











  • Your compiler is informing you that you are copying bytes beyond the limits of gprs.accessPoint.apn into accessPoint.apn. Try memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn)<sizeof(gprs.accessPoint.apn)?sizeof(accessPoint.apn):sizeof(gprs.accessPoint.apn));

    – Gunther Schulz
    Mar 22 at 8:44











  • it's not a compilation error it's risen from klocwork static

    – kessi
    Mar 22 at 8:55











  • The message is rather straight forward. You access the smaller array with the length of the larger array. You need to use the minimum of both sizes and handle the extra elements in the destination separately.

    – Gerhardh
    Mar 22 at 11:31

















-3















I'm getting "Buffer Overflow - Array Index Out of Bounds" for the following code :



typedef struct 
char apn[100 + 1];
char user[22 + 1];
char pass[22 + 1];
GprsParam_t;
typedef struct IfConfig_s
Eth_t eth;
Gprs_t gprs;
Wifi_t wifi;
IfConfig_t;
typedef struct
char apn[64];
char user[32];
char pass[16];
Gprs_t;
gprsParam_t accessPoint;
memset(accessPoint, 0x00, sizeof(accessPoint);
memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn));


I'm trying to copy the value of apn in Gprs_t struct to apn in gprsParam_t
when the sizeof accessPoint.apn is 100 while the sizeof gprs.accessPoint.apn is 64. but it's causing klockwork issue :
Array 'apn' of size 64 may use index value(s) 64..100



I need help understanding this issue.










share|improve this question
























  • What is accessPoint.apn? What is gprs.accessPoint.apn? Please create a Minimal, Complete, and Verifiable example that replicates your problem to show us. Also please take some time to refresh how to ask good questions, as well as this question checklist.

    – Some programmer dude
    Mar 22 at 8:40












  • We need to see a Minimal, Complete, and Verifiable example for this problem.

    – Sourav Ghosh
    Mar 22 at 8:40











  • Your compiler is informing you that you are copying bytes beyond the limits of gprs.accessPoint.apn into accessPoint.apn. Try memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn)<sizeof(gprs.accessPoint.apn)?sizeof(accessPoint.apn):sizeof(gprs.accessPoint.apn));

    – Gunther Schulz
    Mar 22 at 8:44











  • it's not a compilation error it's risen from klocwork static

    – kessi
    Mar 22 at 8:55











  • The message is rather straight forward. You access the smaller array with the length of the larger array. You need to use the minimum of both sizes and handle the extra elements in the destination separately.

    – Gerhardh
    Mar 22 at 11:31













-3












-3








-3


1






I'm getting "Buffer Overflow - Array Index Out of Bounds" for the following code :



typedef struct 
char apn[100 + 1];
char user[22 + 1];
char pass[22 + 1];
GprsParam_t;
typedef struct IfConfig_s
Eth_t eth;
Gprs_t gprs;
Wifi_t wifi;
IfConfig_t;
typedef struct
char apn[64];
char user[32];
char pass[16];
Gprs_t;
gprsParam_t accessPoint;
memset(accessPoint, 0x00, sizeof(accessPoint);
memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn));


I'm trying to copy the value of apn in Gprs_t struct to apn in gprsParam_t
when the sizeof accessPoint.apn is 100 while the sizeof gprs.accessPoint.apn is 64. but it's causing klockwork issue :
Array 'apn' of size 64 may use index value(s) 64..100



I need help understanding this issue.










share|improve this question
















I'm getting "Buffer Overflow - Array Index Out of Bounds" for the following code :



typedef struct 
char apn[100 + 1];
char user[22 + 1];
char pass[22 + 1];
GprsParam_t;
typedef struct IfConfig_s
Eth_t eth;
Gprs_t gprs;
Wifi_t wifi;
IfConfig_t;
typedef struct
char apn[64];
char user[32];
char pass[16];
Gprs_t;
gprsParam_t accessPoint;
memset(accessPoint, 0x00, sizeof(accessPoint);
memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn));


I'm trying to copy the value of apn in Gprs_t struct to apn in gprsParam_t
when the sizeof accessPoint.apn is 100 while the sizeof gprs.accessPoint.apn is 64. but it's causing klockwork issue :
Array 'apn' of size 64 may use index value(s) 64..100



I need help understanding this issue.







c buffer-overflow klocwork






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 8:48







kessi

















asked Mar 22 at 8:39









kessikessi

14212




14212












  • What is accessPoint.apn? What is gprs.accessPoint.apn? Please create a Minimal, Complete, and Verifiable example that replicates your problem to show us. Also please take some time to refresh how to ask good questions, as well as this question checklist.

    – Some programmer dude
    Mar 22 at 8:40












  • We need to see a Minimal, Complete, and Verifiable example for this problem.

    – Sourav Ghosh
    Mar 22 at 8:40











  • Your compiler is informing you that you are copying bytes beyond the limits of gprs.accessPoint.apn into accessPoint.apn. Try memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn)<sizeof(gprs.accessPoint.apn)?sizeof(accessPoint.apn):sizeof(gprs.accessPoint.apn));

    – Gunther Schulz
    Mar 22 at 8:44











  • it's not a compilation error it's risen from klocwork static

    – kessi
    Mar 22 at 8:55











  • The message is rather straight forward. You access the smaller array with the length of the larger array. You need to use the minimum of both sizes and handle the extra elements in the destination separately.

    – Gerhardh
    Mar 22 at 11:31

















  • What is accessPoint.apn? What is gprs.accessPoint.apn? Please create a Minimal, Complete, and Verifiable example that replicates your problem to show us. Also please take some time to refresh how to ask good questions, as well as this question checklist.

    – Some programmer dude
    Mar 22 at 8:40












  • We need to see a Minimal, Complete, and Verifiable example for this problem.

    – Sourav Ghosh
    Mar 22 at 8:40











  • Your compiler is informing you that you are copying bytes beyond the limits of gprs.accessPoint.apn into accessPoint.apn. Try memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn)<sizeof(gprs.accessPoint.apn)?sizeof(accessPoint.apn):sizeof(gprs.accessPoint.apn));

    – Gunther Schulz
    Mar 22 at 8:44











  • it's not a compilation error it's risen from klocwork static

    – kessi
    Mar 22 at 8:55











  • The message is rather straight forward. You access the smaller array with the length of the larger array. You need to use the minimum of both sizes and handle the extra elements in the destination separately.

    – Gerhardh
    Mar 22 at 11:31
















What is accessPoint.apn? What is gprs.accessPoint.apn? Please create a Minimal, Complete, and Verifiable example that replicates your problem to show us. Also please take some time to refresh how to ask good questions, as well as this question checklist.

– Some programmer dude
Mar 22 at 8:40






What is accessPoint.apn? What is gprs.accessPoint.apn? Please create a Minimal, Complete, and Verifiable example that replicates your problem to show us. Also please take some time to refresh how to ask good questions, as well as this question checklist.

– Some programmer dude
Mar 22 at 8:40














We need to see a Minimal, Complete, and Verifiable example for this problem.

– Sourav Ghosh
Mar 22 at 8:40





We need to see a Minimal, Complete, and Verifiable example for this problem.

– Sourav Ghosh
Mar 22 at 8:40













Your compiler is informing you that you are copying bytes beyond the limits of gprs.accessPoint.apn into accessPoint.apn. Try memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn)<sizeof(gprs.accessPoint.apn)?sizeof(accessPoint.apn):sizeof(gprs.accessPoint.apn));

– Gunther Schulz
Mar 22 at 8:44





Your compiler is informing you that you are copying bytes beyond the limits of gprs.accessPoint.apn into accessPoint.apn. Try memcpy(accessPoint.apn, gprs.accessPoint.apn, sizeof(accessPoint.apn)<sizeof(gprs.accessPoint.apn)?sizeof(accessPoint.apn):sizeof(gprs.accessPoint.apn));

– Gunther Schulz
Mar 22 at 8:44













it's not a compilation error it's risen from klocwork static

– kessi
Mar 22 at 8:55





it's not a compilation error it's risen from klocwork static

– kessi
Mar 22 at 8:55













The message is rather straight forward. You access the smaller array with the length of the larger array. You need to use the minimum of both sizes and handle the extra elements in the destination separately.

– Gerhardh
Mar 22 at 11:31





The message is rather straight forward. You access the smaller array with the length of the larger array. You need to use the minimum of both sizes and handle the extra elements in the destination separately.

– Gerhardh
Mar 22 at 11:31












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295739%2fbuffer-overflow-array-index-out-of-bounds-when-arrays-sizes-are-correctly-ma%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55295739%2fbuffer-overflow-array-index-out-of-bounds-when-arrays-sizes-are-correctly-ma%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?