“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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript